教你如何在Centos8-stream安裝PostgreSQL13
一、安裝postgresql13-server
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm yum install -y postgresql13-server
二、初始化PostgreSQL
先創(chuàng)建postgresql儲存目錄
mkdir /home/pgsql-13 chmod 777 /home/pgsql-13 #授予權(quán)限,否則后續(xù)初始化是會報(bào)錯
切換postgres用戶正式初始化
su postgres /usr/pgsql-13/bin/initdb -D /home/pgsql-13/data
三、啟動postgresql數(shù)據(jù)庫
cd /home/pgsql-13 /usr/pgsql-13/bin/pg_ctl -D /home/pgsql-13/data -l logfile start
這里注意繼續(xù)使用postgres用戶操作,否則會報(bào)錯
四、修改配置文件和創(chuàng)建數(shù)據(jù)庫密碼和數(shù)據(jù)庫
vi /home/pgsql-13/data/postgresql.conf listen_addresses = ‘localhost' #開放本地登錄 port = 5432 #開放登錄端口 psql ALTER USER postgres WITH PASSWORD '(123456)'; #將123456替換成自己設(shè)定的數(shù)據(jù)庫密碼 CREATE DATABASE mytest; #創(chuàng)建數(shù)據(jù)庫 \q #退出操作
結(jié)果如下圖:
五、添加遠(yuǎn)程訪問權(quán)限:
vi /home/pgsql-13/data/pg_hba.conf host all all 0.0.0.0/0 md5 #結(jié)尾處添加
六、配置開機(jī)啟動數(shù)據(jù)庫腳本
mkdir /home/pgsql-13/bin vi /home/pgsql-13/bin/startup.sh
輸入一下內(nèi)容:
#! /bin/bash su postgres<<! cd /home/pgsql-13 /usr/pgsql-13/bin/pg_ctl -D /home/pgsql-13/data -l logfile start exit $? !
添加腳本路徑
chmod -R 755 startup.sh vi /etc/rc.local /home/pgsql-13/bin/startup.sh #在文件內(nèi)容最后一行添加
七、數(shù)據(jù)庫定時(shí)備份腳本
mkdir -p /home/pgsql-13/backdata chmod 777 /home/pgsql-13/backdata mkdir -p /home/pgsql-13/backdata/bin vi /home/pgsql-13/backdata/bin/backup.sh
輸入如下內(nèi)容:
#! /bin/bash t=KaTeX parse error: Expected group after '_' at position 112: …ip > backupfile_?t.sql.gz find /home/pgsql-13/backdata -mtime 7 -type f|xargs rm -f exit $? !
配置定時(shí)任務(wù):
12 2 * * * /home/pgsql-13/backdata/bin/backup.sh
參考網(wǎng)站:https://www.postgresql.org/download/linux/redhat/
PostgreSQL 13.1 手冊 http://postgres.cn/docs/13/index.html
到此這篇關(guān)于Centos8-stream安裝PostgreSQL13的文章就介紹到這了,更多相關(guān)Centos8安裝PostgreSQL13內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。