postgresql源碼安裝
1.下載源碼
cd /usr/local
wget https://ftp.postgresql.org/pub/source/v10.6/postgresql-10.6.tar.gz --no-check-certificate
2.解壓
tar -zvxf postgresql-10.6.tar.gz
3.編譯安裝
3.1.安裝配置
cd postgresql-10.6 ./configure --help # 安裝依賴包 yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake #./configure --prefix=/usr/local/postgresql --with-segsize=16 --with-blocksize=32 --with-wal-segsize=64 --with-wal-blocksize=64 --with-libedit-preferred --with-perl --with-python --with-openssl --with-libxml --with-libxslt --enable-thread-safety --enable-nls=en_US.UTF-8 ./configure --prefix=/usr/local/postgresql --with-wal-segsize=512 --with-wal-blocksize=16 --with-pgport=5432 --with-segsize=1 --with-blocksize=8 --with-libedit-preferred --with-perl --with-openssl --with-libxml --with-libxslt --enable-thread-safety --enable-nls=en_US.UTF-8
segsize:段尺寸,操作系統對文件的大小限制,因此一個表的文件最大不能超過文件系統規定的大小。為解決這個問題,可以將大表的文件拆分為小文件,每個文件的大小即為段設置的大小,單位為G
blocksize:塊大小,數據庫IO的最小單位
wal-segsize:日志段大小,即日志的大小
wal-blocksize:日志塊大小,日志的最小IO單位
具體的參數可以根據實際需求修改
3.2.編譯
make
3.3.安裝
make install
4.創建postgresql用戶,數據目錄,日志目錄、
useradd postgres
mkdir /usr/local/postgresql/{data,logs}
chown postgres.postgres -R /usr/local/postgresql
5.安裝擴展
cd /usr/local/postgresql-10.6/contrib more README make all make install
6.初始化數據庫
./pg_ctl -D /usr/local/postgresql/data initdb
7.啟動數據庫
/usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data -l /usr/local/postgresql/logs/server.log start
8.設置遠程訪問
#設置監聽整個網絡,查找“listen_addresses ”字符串, vim /usr/local/postgresql/data/postgresql.conf #修改為如下: listen_addresses = '*' #配置連接方式: vim /usr/local/postgresql/data/pg_hba.conf #修改為如下: host all all 0.0.0.0/0 md5
9.連接postgresql
bin/psql -U postgres 或者 bin/psql -d postgres
10.創建用戶
postgres=# CREATE USER postgres SUPERUSER; CREATE ROLE postgres=# alter user postgres with password '123456'; ALTER ROLE postgres=#
bin/psql -h 192.168.2.72 -U postgres -p 5432 Password for user postgres: psql (10.6) Type "help" for help. postgres=#
#創建用戶 CREATE USER dbuser; #創建數據庫 CREATE DATABASE access_data OWNER dbuser;
#修改密碼
alter user postgres with password '123456';
bin/psql -h 192.168.15.72 -U dbuser -d access_data -p 5432 Password for user dbuser: psql (10.6) Type "help" for help.
access_data=>
11. 設置環境變量
編輯 /etc/profile 文件,在末尾加入:
export PG_HOME=/opt/local/postgres
export PATH=$PG_HOME/bin:$PATH
再次執行 source /etc/profile即完成環境變量設置。
接下來,需要設置動態鏈接庫的加載路徑(LD_LIBRARY_PATH),否則會報找不到libpq.so.5的錯誤,如下:
./psql: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory
設置鏈接庫路徑
sudo /sbin/ldconfig /opt/local/pgsql/lib
或通過編輯/etc/profile,加入:
LD_LIBRARY_PATH=/usr/local/pgsql/lib
export LD_LIBRARY_PATH