debian12部署PostgreSQL

660 阅读1分钟

添加仓库并安装软件包

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

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

# Update the package lists:
sudo apt-get update

# Install the latest version of PostgreSQL.
# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql':
sudo apt-get -y install postgresql

查看PostgreSQL默认数据目录

前面步骤安装的为最新版本15,默认数据目录为/var/lib/postgresql/15/main/

root@node1:~# ls -al /var/lib/postgresql/15/main/
total 92
drwx------ 19 postgres postgres 4096 Jul 16 08:47 .
drwxr-xr-x  3 postgres postgres 4096 Jul 16 08:47 ..
drwx------  5 postgres postgres 4096 Jul 16 08:47 base
drwx------  2 postgres postgres 4096 Jul 16 08:49 global
drwx------  2 postgres postgres 4096 Jul 16 08:47 pg_commit_ts
drwx------  2 postgres postgres 4096 Jul 16 08:47 pg_dynshmem
drwx------  4 postgres postgres 4096 Jul 16 08:47 pg_logical
drwx------  4 postgres postgres 4096 Jul 16 08:47 pg_multixact
drwx------  2 postgres postgres 4096 Jul 16 08:47 pg_notify
drwx------  2 postgres postgres 4096 Jul 16 08:47 pg_replslot
drwx------  2 postgres postgres 4096 Jul 16 08:47 pg_serial
drwx------  2 postgres postgres 4096 Jul 16 08:47 pg_snapshots
drwx------  2 postgres postgres 4096 Jul 16 08:47 pg_stat
drwx------  2 postgres postgres 4096 Jul 16 08:47 pg_stat_tmp
drwx------  2 postgres postgres 4096 Jul 16 08:47 pg_subtrans
drwx------  2 postgres postgres 4096 Jul 16 08:47 pg_tblspc
drwx------  2 postgres postgres 4096 Jul 16 08:47 pg_twophase
-rw-------  1 postgres postgres    3 Jul 16 08:47 PG_VERSION
drwx------  3 postgres postgres 4096 Jul 16 08:47 pg_wal
drwx------  2 postgres postgres 4096 Jul 16 08:47 pg_xact
-rw-------  1 postgres postgres   88 Jul 16 08:47 postgresql.auto.conf
-rw-------  1 postgres postgres  130 Jul 16 08:47 postmaster.opts
-rw-------  1 postgres postgres  108 Jul 16 08:47 postmaster.pid

切换到postgres用户连接数据库

root@node1:~# su - postgres 
postgres@node1:~$ psql
psql (15.3 (Debian 15.3-0+deb12u1))
Type "help" for help.

postgres=# 

输入\q可以退出

root@node1:~# su - postgres 
postgres@node1:~$ psql
psql (15.3 (Debian 15.3-0+deb12u1))
Type "help" for help.

postgres=# \q
postgres@node1:~$