CentOS系統中安裝postgresql的rpm源
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
安裝用戶端:
yum install postgresql11yum install postgresql11
安裝服務端:
yum install postgresql11-server
yum install postgresql11-develyum install postgresql11-devel
初始化資料庫:
/usr/pgsql-11/bin/postgresql-11-setup initdb/usr/pgsql-11/bin/postgresql-11-setup initdb
啟動資料庫并設定開機啟動:
systemctl enable postgresql-11
systemctl start postgresql-11
登入PostgreSQL并設定密碼
su root #首先擷取root權限
su - postgres #登入資料庫
psql
設定密碼:
ALTER USER postgres WITH PASSWORD '密碼';
\q 退出
\l 列出所有庫
\du 列出所有使用者
\d 列出庫下所有表
預設情況下postgresql是不用密碼不支援遠端登入的。需要修改配置檔案:
vi /var/lib/pgsql/11/data/pg_hba.conf
修改前:

修改後:
vi /var/lib/pgsql/11/data/postgresql.conf
重新開機postgresql
systemctl restart postgresql-11