日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

教你如何在Centos8-stream安裝PostgreSQL13_PostgreSQL

作者:菲宇 ? 更新時間: 2022-04-28 編程語言

一、安裝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

先創建postgresql儲存目錄

mkdir /home/pgsql-13
chmod 777 /home/pgsql-13  #授予權限,否則后續初始化是會報錯

切換postgres用戶正式初始化

su postgres     
/usr/pgsql-13/bin/initdb -D /home/pgsql-13/data

在這里插入圖片描述

三、啟動postgresql數據庫

cd  /home/pgsql-13
/usr/pgsql-13/bin/pg_ctl -D /home/pgsql-13/data -l logfile start

這里注意繼續使用postgres用戶操作,否則會報錯

在這里插入圖片描述

四、修改配置文件和創建數據庫密碼和數據庫

vi /home/pgsql-13/data/postgresql.conf
listen_addresses = ‘localhost'   #開放本地登錄
port = 5432          #開放登錄端口
psql
ALTER USER postgres WITH PASSWORD '(123456)'; #將123456替換成自己設定的數據庫密碼
CREATE DATABASE mytest;  #創建數據庫
\q  #退出操作

結果如下圖:

在這里插入圖片描述

五、添加遠程訪問權限:

vi /home/pgsql-13/data/pg_hba.conf
host       all       all        0.0.0.0/0      md5  #結尾處添加

在這里插入圖片描述

六、配置開機啟動數據庫腳本

mkdir /home/pgsql-13/bin
vi /home/pgsql-13/bin/startup.sh

輸入一下內容:

#! /bin/bash
su postgres<

添加腳本路徑

chmod -R 755 startup.sh
vi /etc/rc.local
/home/pgsql-13/bin/startup.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

輸入如下內容:

#! /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 $?
!

配置定時任務:

12 2 * * * /home/pgsql-13/backdata/bin/backup.sh

參考網站:https://www.postgresql.org/download/linux/redhat/
PostgreSQL 13.1 手冊 http://postgres.cn/docs/13/index.html

原文鏈接:https://blog.csdn.net/bbwangj/article/details/123114413

欄目分類
最近更新