安装

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

sudo apt-get update

sudo apt-get -y install postgresql

sudo systemctl stop postgresql

修改配置

vim /etc/postgresql/14/main/postgresql.conf

listen_addresses = '*'

vim /etc/postgresql/14/main/pg_hba.conf

host    all             all             0.0.0.0/0              md5

修改储存位置

cp -a /var/lib/postgresql /opt/data/

mv -u /var/lib/postgresql /var/lib/postgresql.bak

sudo ln -fs /opt/data/postgresql /var/lib/postgresql

sudo systemctl start postgresql

创建超级用户

sudo -u postgres psql

CREATE ROLE admin WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD '0000';

管理应用程序用户

CREATE DATABASE sync TEMPLATE template0 ENCODING UTF8 LC_COLLATE 'zh_CN.UTF-8' LC_CTYPE 'zh_CN.UTF-8'; 

发现报错

处理过程, 执行如下命令:

apt-get install locales
dpkg-reconfigure locales

重启 reboot

CREATE DATABASE sync TEMPLATE template0 ENCODING UTF8 LC_COLLATE 'zh_CN.UTF-8' LC_CTYPE 'zh_CN.UTF-8';  
create user sync with encrypted password '0000';
grant all privileges on database sync to sync;