postgresql-13 的安裝
這篇文章的撰寫時間是postgresql13.1之后發布的,是最簡單粗暴的指導,沒有之一,
我已經幫大家踩完坑了,直接按步驟來就行了,
- 先更新安裝源,如下:
sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum -y update
sudo yum -y update
- 安裝postgresql13
sudo yum -y install postgresql13-server
- 初始化資料庫(如果想改變資料庫存盤位置,可以跳過這步)
$ sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database ... OK
#啟動服務
$ systemctl start postgresql-13
#允許服務開機運行
$ systemctl enable postgresql-13
postgresql-13 修改初始化資料路徑
1. 更改資料存盤位置
這里介紹systemctl 的使用如下:
systemctl edit postgresql-13.service
在新空白頁覆寫原服務配置
[Service]
Environment=PGDATA=/data/pgdata
這個檔案默認放在 /etc/systemd/system/postgresql-13.service.d 目錄下,
里面會有 override.conf 檔案,
2. 創建檔案夾權限問題
當你執行這個命令時候,你會發現資料庫創建沒有回傳‘OK’,我的天啊,而且直接閃退,
$ /usr/pgsql-13/bin/postgresql-13-setup initdb
如果使用 systemctl start postgresql-13 命令的時候你會發現不好使,
其實際原因可以查看 more /var/lib/pgsql/13/initdb.log 的日志,你會發現如下錯誤:
Data page checksums are disabled.
fixing permissions on existing directory /data/pgdata ... initdb: error: could not change permissions of directory "/data/pgdata": Operation not permitted
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
意思是指這個檔案夾不是postgres創建的,所以你要通過postgres創建這個檔案夾,就可以了,
$ su - postgres
$ cd /data
$ mkdir ./pgdata
然后你在試下:
$ /usr/pgsql-13/bin/postgresql-13-setup initdb
Create Database.
Ok.
systemctl start postgresql-13.service
systemctl enable postgresql-13.service
貌似沒有錯誤了,
3. 修改postgres默認密碼
# 切換到 postgres 用戶
$ sudo -u postgres psql
psql (13.1)
Type "help" for help.
postgres=# ALTER USER postgres WITH PASSWORD ‘postgres’;
4. 修改登錄方式
首先修改 /var/lib/pgsql/10/data/postgresql.conf
listen_address = '*'
password_encryption = 'md5'
在修改 /var/lib/pgsql/10/data/pg_hba.conf, 如下
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
#host all all 127.0.0.1/32 scram-sha-256
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
但是我發現,nodejs連接postgresql-13 是好使了,但是navicate不行,原因是postgresql-13 改動還是不小的,安全加密策略有變化和完善,現在已經使用scram-sha-256方式了,
沒招把md5 改為 password 方式就ok了,也都正常了,如下:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
#host all all 127.0.0.1/32 scram-sha-256
host all all 0.0.0.0/0 password
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/239112.html
標籤:其他
上一篇:PHP操作Redis常用命令
