postgresql安裝與登入
阿新 • • 發佈:2022-03-24
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 192.168.2.0/24 md5
9.連線postgresql
bin/psql -U 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