系列1 安裝部署和初始化

1. 官網(wǎng)資料

https://www.postgresql.org/download/

2. 二進(jìn)制安裝

查詢官網(wǎng)資料https://www.postgresql.org/download/

3. 源碼安裝部署

示例(基于Ubuntu 22.04):

apt install build-essential libreadline-dev zlib1g-dev
./configure --prefix=/opt/postgresql
make
make install
adduser postgres
mkdir -p /opt/pgsql/data
chown postgres /opt/pgsql/data
su - postgres
/opt/postgresql/bin/initdb -D /opt/pgsql/data
/opt/postgresql/bin/postgres -D /opt/pgsql/data >logfile 2>&1 &
/opt/postgresql/bin/createdb test
/opt/postgresql/bin/psql test

4. 停啟pg服務(wù)

4.1 啟動(dòng)命令
方案1:pg_ctl命令
/opt/postgresql/bin/pg_ctl -D /opt/pgsql/data -l logfile start
方案2:postgres命令
/opt/postgresql/bin/postgres -D /opt/pgsql/data >logfile 2>&1 &
方案3:systemctl命令
編輯postgresql.service
systemctl start postgresql
4.2 關(guān)閉命令
方案1:pg_ctl命令
/opt/postgresql/bin/pg_ctl -D /opt/pgsql/data stop
方案2:systemctl命令
編輯postgresql.service
systemctl stop postgresql
方案3:kill命令
kill -INT `head -1 /opt/pgsql/data/postmaster.pid`

5. 配置文件

有三種與配置相關(guān)的配置文件
1)主服務(wù)器配置文件(通常稱為postgresql.conf)。
2)指定用于基于主機(jī)的身份驗(yàn)證(通常稱為 )的配置文件pg_hba.conf。此參數(shù)只能在服務(wù)器啟動(dòng)時(shí)設(shè)置。
3)指定用戶名映射的配置文件(習(xí)慣上稱為pg_ident.conf)。此參數(shù)只能在服務(wù)器啟動(dòng)時(shí)設(shè)置。另見第 21.2 節(jié)。

6. 基于初始化信息的一些有趣改動(dòng)

1)修改默認(rèn)的超級(jí)用戶postgres,例如改為pguser

方案一:
adduser pguser
mkdir -p /opt/pgsql/data2
chown pguser /opt/pgsql/data2
su - pguser
/opt/postgresql/bin/initdb -D /opt/pgsql/data2
/opt/postgresql/bin/postgres -D /opt/pgsql/data2 >logfile 2>&1 &
方案二:
adduser postgres
mkdir -p /opt/pgsql/data
chown postgres /opt/pgsql/data
su - postgres
/opt/postgresql/bin/initdb -U pguser -D /opt/pgsql/data
/opt/postgresql/bin/postgres -D /opt/pgsql/data >logfile 2>&1 &
# 查看
psql -Upguser postgres

2)修改初始化數(shù)據(jù)庫(kù)postgres,例如初始化數(shù)據(jù)庫(kù)改為testdb
未找到方案
3)刪除默認(rèn)postgres數(shù)據(jù)庫(kù)
dropdb postgres;
testdb=# drop database postgres;
4)刪除模板數(shù)據(jù)庫(kù)(自坑操作)
alter database template0 is_template false;
alter database template1 is_template false;
drop database template0;
drop database template1;
注意,刪除完,新建數(shù)據(jù)庫(kù)就沒有默認(rèn)模板可以使用了,于是create database xxx新建不了數(shù)據(jù)庫(kù)。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容