centos7 linux安裝 postgresql 10.1
阿新 • • 發佈:2018-11-09
官網也有安裝的方式,我習慣了編譯安裝。 總結編譯安裝的方式:
第一種 yum安裝:
每一行代表一行命令
yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm yum install postgresql10 yum install postgresql10-server /usr/pgsql-10/bin/postgresql-10-setup initdb systemctl enable postgresql-10 systemctl start postgresql-10
可以參考pgsql的官網 都給予了安裝方式
https://www.postgresql.org/download/linux/redhat/
-
登入命令: psql -U postgres 會進入postgres使用者的控制檯
-
執行:psql -U postgres 或者 sudo -u postgres psql 可以進入資料庫
-
\l 檢視有哪些資料庫
-
\c postgresql 選擇postgresql 這個資料庫,會提示進入連線
建立使用者:create user username with login password 'password';
修改登入PostgreSQL密碼 ALTER USER postgres WITH PASSWORD 'postgres';
允許遠端訪問配置:
修改 PostgreSQL 配置檔案 postgresql.conf
我的配置檔案在 /var/lib/pgsql/10/data/postgresql.conf
把 listen_addresses = 'localhost'
改為 listen_addresses = '*'
重啟 即可
使用遠端工具連線時如果無法連線
vim /var/lib/pgsql/10/data/pg_hba.conf 則新增到86行左右 #自行新增 喬永剛 host all all 0.0.0.0/0 md5
進入pgsql
先切換到postgresql使用者
su postgresql
psql -U postgres
-----------------------------------------------------------------------------------------------------------------------------------------------
第二種 編譯安裝
第一步:
開啟pgsql的官網下載tar包
地址:
https://www.postgresql.org/ftp/source/v10.1/
解壓完畢
第二步 :
./configure
此時可能會報錯:
configure: error: readline library not found
如果報錯則執行:
yum -y install -y readline-devel
參考地址:https://www.linuxidc.com/Linux/2012-02/53982.htm
第三步:
make && make install
最終提示:
make[1]: Leaving directory `/root/postgresql-10.1/src'
make -C config install
make[1]: Entering directory `/root/postgresql-10.1/config'
/usr/bin/mkdir -p '/usr/local/pgsql/lib/pgxs/config'
/usr/bin/install -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/config/install-sh'
/usr/bin/install -c -m 755 ./missing '/usr/local/pgsql/lib/pgxs/config/missing'
make[1]: Leaving directory `/root/postgresql-10.1/config'
PostgreSQL installation complete.
安裝成功