【ubuntu 18.04】安装postgres14

1. 官网

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

文档

PostgreSQL: Documentation

 

2. 安装

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 # 默认安装最新14

3. 初始化账号密码

sudo -u postgres psql
postgres=# alter user postgres with password '123456';

# 若要删除该管理员的密码(非必须)
# sudo -u postgres psql -d postgres

4. 配置远程访问

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

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

 

 重启服务生效

sudo systemctl restart postgresql.service

5. 测试远程访问,输入之前修改的密码即可

master@master:~$ psql -U postgres -h 192.168.10.248 
Password for user postgres: 
psql (13.5 (Ubuntu 13.5-1.pgdg18.04+1), server 14.1 (Ubuntu 14.1-1.pgdg18.04+1))
WARNING: psql major version 13, server major version 14.
         Some psql features might not work.
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

postgres=# 

6. 常用操作

sudo systemctl restart postgresql.service
sudo systemctl start postgresql.service
sudo systemctl stop postgresql.service
sudo systemctl status postgresql.service
# or
sudo /etc/init.d/postgresql status
sudo /etc/init.d/postgresql start
sudo /etc/init.d/postgresql stop
sudo /etc/init.d/postgresql restart
# or
sudo service postgresql restart
sudo service postgresql start
sudo service postgresql stop
sudo service postgresql status

6. 卸载

tester@fabu:~$ sudo dpkg --get-selections | grep postgres  # 或者sudo dpkg -l | grep postgres
postgresql                                      install
postgresql-14                                   install
postgresql-client-14                            install
postgresql-client-common                        install
postgresql-common                               install
sudo service postgresql stop 
sudo apt-get --purge remove postgresql\*
sudo rm -r /etc/postgresql/
sudo rm -r /etc/postgresql-common/
sudo rm -r /var/lib/postgresql/
sudo userdel -r postgres
sudo groupdel postgres
posted @ 2021-12-28 14:42  代码诠释的世界  阅读(1214)  评论(0编辑  收藏  举报