首页 > 数据库 >Debian 11 上安装 postgresql

Debian 11 上安装 postgresql

时间:2024-07-22 13:41:20浏览次数:17  
标签:11 ... postgresql amd64 16 perl Debian pgdg110

1.增加官方的Repository

手动配置官方的 apt Repository

# Import the repository signing key:
$ sudo apt install curl ca-certificates
$ sudo install -d /usr/share/postgresql-common/pgdg
$ sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc

# Create the repository configuration file:
$ sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

2.更新系统包

$ sudo apt update

3.安装和配置 postgresql 16

$ sudo apt install postgresql-16
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libcommon-sense-perl libjson-perl libjson-xs-perl libllvm13 libpq5 libtypes-serialiser-perl libz3-4 postgresql-client-16 postgresql-client-common postgresql-common ssl-cert
Suggested packages:
  postgresql-doc-16
The following NEW packages will be installed:
  libcommon-sense-perl libjson-perl libjson-xs-perl libllvm13 libpq5 libtypes-serialiser-perl libz3-4 postgresql-16 postgresql-client-16 postgresql-client-common postgresql-common ssl-cert
0 upgraded, 12 newly installed, 0 to remove and 101 not upgraded.
Need to get 47.3 MB of archives.
After this operation, 193 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.ustc.edu.cn/debian bullseye/main amd64 libjson-perl all 4.03000-1 [88.6 kB]
Get:2 http://mirrors.ustc.edu.cn/debian bullseye/main amd64 ssl-cert all 1.1.0+nmu1 [21.0 kB]
Get:3 http://mirrors.ustc.edu.cn/debian bullseye/main amd64 libcommon-sense-perl amd64 3.75-1+b4 [24.6 kB]
Get:4 http://mirrors.ustc.edu.cn/debian bullseye/main amd64 libtypes-serialiser-perl all 1.01-1 [12.2 kB]
Get:5 http://mirrors.ustc.edu.cn/debian bullseye/main amd64 libjson-xs-perl amd64 4.030-1+b1 [94.9 kB]
Get:6 http://mirrors.ustc.edu.cn/debian bullseye/main amd64 libz3-4 amd64 4.8.10-1 [6,949 kB]
Get:7 http://mirrors.ustc.edu.cn/debian bullseye/main amd64 libllvm13 amd64 1:13.0.1-6~deb11u1 [20.1 MB]
Get:8 https://apt.postgresql.org/pub/repos/apt bullseye-pgdg/main amd64 postgresql-client-common all 261.pgdg110+1 [94.7 kB]
Get:9 https://apt.postgresql.org/pub/repos/apt bullseye-pgdg/main amd64 postgresql-common all 261.pgdg110+1 [240 kB]
Get:10 https://apt.postgresql.org/pub/repos/apt bullseye-pgdg/main amd64 libpq5 amd64 16.3-1.pgdg110+1 [217 kB]
Get:11 https://apt.postgresql.org/pub/repos/apt bullseye-pgdg/main amd64 postgresql-client-16 amd64 16.3-1.pgdg110+1 [1,901 kB]                                                                                                                          
Get:12 https://apt.postgresql.org/pub/repos/apt bullseye-pgdg/main amd64 postgresql-16 amd64 16.3-1.pgdg110+1 [17.5 MB]                                                                                                                                  
Fetched 47.3 MB in 59s (798 kB/s)                                                                                                                                                                                                                        
Preconfiguring packages ...
Selecting previously unselected package libjson-perl.
(Reading database ... 44352 files and directories currently installed.)
Preparing to unpack .../00-libjson-perl_4.03000-1_all.deb ...
Unpacking libjson-perl (4.03000-1) ...
Selecting previously unselected package postgresql-client-common.
Preparing to unpack .../01-postgresql-client-common_261.pgdg110+1_all.deb ...
Unpacking postgresql-client-common (261.pgdg110+1) ...
Selecting previously unselected package ssl-cert.
Preparing to unpack .../02-ssl-cert_1.1.0+nmu1_all.deb ...
Unpacking ssl-cert (1.1.0+nmu1) ...
Selecting previously unselected package postgresql-common.
Preparing to unpack .../03-postgresql-common_261.pgdg110+1_all.deb ...
Adding 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by postgresql-common'
Unpacking postgresql-common (261.pgdg110+1) ...
Selecting previously unselected package libcommon-sense-perl.
Preparing to unpack .../04-libcommon-sense-perl_3.75-1+b4_amd64.deb ...
Unpacking libcommon-sense-perl (3.75-1+b4) ...
Selecting previously unselected package libtypes-serialiser-perl.
Preparing to unpack .../05-libtypes-serialiser-perl_1.01-1_all.deb ...
Unpacking libtypes-serialiser-perl (1.01-1) ...
Selecting previously unselected package libjson-xs-perl.
Preparing to unpack .../06-libjson-xs-perl_4.030-1+b1_amd64.deb ...
Unpacking libjson-xs-perl (4.030-1+b1) ...
Selecting previously unselected package libz3-4:amd64.
Preparing to unpack .../07-libz3-4_4.8.10-1_amd64.deb ...
Unpacking libz3-4:amd64 (4.8.10-1) ...
Selecting previously unselected package libllvm13:amd64.
Preparing to unpack .../08-libllvm13_1%3a13.0.1-6~deb11u1_amd64.deb ...
Unpacking libllvm13:amd64 (1:13.0.1-6~deb11u1) ...
Selecting previously unselected package libpq5:amd64.
Preparing to unpack .../09-libpq5_16.3-1.pgdg110+1_amd64.deb ...
Unpacking libpq5:amd64 (16.3-1.pgdg110+1) ...
Selecting previously unselected package postgresql-client-16.
Preparing to unpack .../10-postgresql-client-16_16.3-1.pgdg110+1_amd64.deb ...
Unpacking postgresql-client-16 (16.3-1.pgdg110+1) ...
Selecting previously unselected package postgresql-16.
Preparing to unpack .../11-postgresql-16_16.3-1.pgdg110+1_amd64.deb ...
Unpacking postgresql-16 (16.3-1.pgdg110+1) ...
Setting up postgresql-client-common (261.pgdg110+1) ...
Setting up libpq5:amd64 (16.3-1.pgdg110+1) ...
Setting up libcommon-sense-perl (3.75-1+b4) ...
Setting up libz3-4:amd64 (4.8.10-1) ...
Setting up ssl-cert (1.1.0+nmu1) ...
Setting up libllvm13:amd64 (1:13.0.1-6~deb11u1) ...
Setting up libtypes-serialiser-perl (1.01-1) ...
Setting up libjson-perl (4.03000-1) ...
Setting up libjson-xs-perl (4.030-1+b1) ...
Setting up postgresql-client-16 (16.3-1.pgdg110+1) ...
update-alternatives: using /usr/share/postgresql/16/man/man1/psql.1.gz to provide /usr/share/man/man1/psql.1.gz (psql.1.gz) in auto mode
Setting up postgresql-common (261.pgdg110+1) ...
Adding user postgres to group ssl-cert

Creating config file /etc/postgresql-common/createcluster.conf with new version
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /lib/systemd/system/postgresql.service.
Setting up postgresql-16 (16.3-1.pgdg110+1) ...
Creating new PostgreSQL cluster 16/main ...
/usr/lib/postgresql/16/bin/initdb -D /var/lib/postgresql/16/main --auth-local peer --auth-host scram-sha-256 --no-instructions
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/16/main ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for libc-bin (2.31-13+deb11u5) ...

安装完成后会在/etc/下生成两个目录:postgresql、postgresql-common

$ sudo tree postgresql
postgresql
└── 16
    └── main
        ├── conf.d
        ├── environment
        ├── pg_ctl.conf
        ├── pg_hba.conf
        ├── pg_ident.conf
        ├── postgresql.conf
        └── start.conf

3 directories, 6 files
$ sudo tree postgresql-common/
postgresql-common/
├── createcluster.conf
├── pg_upgradecluster.d
│   └── analyze
├── root.crt
├── supported_versions
└── user_clusters

1 directory, 5 files

版本检查

$ sudo psql --version
psql (PostgreSQL) 16.3 (Debian 16.3-1.pgdg110+1)
root@test1:/etc/postgresql/16/main# sudo -u postgres psql -c "select version();"
                                                           version                                                           
-----------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 16.3 (Debian 16.3-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
(1 row)

监听配置

$ sudo vim /etc/postgresql/16/main/postgresql.conf
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - Connection Settings -

listen_addresses = '*'          # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for al

开启密码登录

$ sudo  sed -i '/^host/s/ident/md5/' /etc/postgresql/16/main/pg_hba.conf

将对等标识更改为信任

$ sudo  sed -i '/^local/s/peer/trust/' /etc/postgresql/16/main/pg_hba.conf

开启远程访问

$ sudo  vim /etc/postgresql/16/main/pg_hba.conf
# 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                 scram-sha-256
host    all             all             0.0.0.0/0               md5

4.启动

$ sudo systemctl start postgresql && sudo systemctl enable postgresql
Synchronizing state of postgresql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable postgresql
$ sudo  /lib/systemd/systemd-sysv-install enable postgresql

5.修改超级用户的密码

$ sudo -i -u postgres
postgres@test1:~$ psql
psql (16.3 (Debian 16.3-1.pgdg110+1))
Type "help" for help.

postgres=# ALTER USER postgres PASSWORD 'abcd';

 

标签:11,...,postgresql,amd64,16,perl,Debian,pgdg110
From: https://www.cnblogs.com/abclife/p/18281430

相关文章

  • 基于开源IM即时通讯框架MobileIMSDK:RainbowChat v11.6版已发布
    关于RainbowChatRainbowChat是一套基于开源IM聊天框架 MobileIMSDK 的产品级移动端IM系统。RainbowChat源于真实运营的产品,解决了大量的屏幕适配、细节优化、机器兼容问题(可自行下载体验:专业版下载安装)。* RainbowChat可能是市面上提供im即时通讯聊天源码的,唯一一款同时支持T......
  • 如何在不停机的情况下向现有的 PostgreSQL 级联复制添加额外的从属服务器?
    步骤1:将第3个从属信息放在从属2的pg_hba.conf中,如果这里没有recovery.conf文件,请立即创建catrecovery.confstandby_mode='on'primary_conninfo='host=192.168.2.3port=5432user=postgrespassword=postgres'#restore_command='cp/archive/%f"%p&......
  • PostgreSQL安装异常:Problem running post-install step
    1.错误详情安装PostgreSQL时快要完成的时候抛出异常Problemrunningpost-installstep.Installationmaynotcompletecorrectlty.Thedatabaseclusterinitialisationfailed.2.解决方法以管理员权限打开PowerShell找到PostgreSQL安装目录,进入bin文件夹(例子中是D:\Post......
  • 题解 P1115 最大子段和
    link容易想到朴素做法:for(intl=1;i<=n;++i){for(intr=1;j<=n;++j){intv=s[r]-s[l-1];ans=max(ans,v);}}但是显然\(\mathrm{\color{#052242}TLE}\)再回头看代码:想要v最大,只需要\(\large{S_{l-1}}\)最小即可......
  • 《深入了解 MEMS LVCMOS 振荡器 SiT2001 系列(1 to 110 MHz)》
    在当今的电子领域,高性能的振荡器对于确保系统的稳定运行和精确计时至关重要。今天,我们将深入探讨一款引人注目的产品——MEMSLVCMOS振荡器SiT2001系列(1to110MHz)。一、SiT2001系列的基本概述MEMSLVCMOS振荡器SiT2001系列涵盖了1至110MHz的广泛频率范围,为......
  • 使用 pip 22.3.1 和 python 3.11.0 安装 MetaTrader5 错误
    我正在尝试使用pip在Windows上安装MetaTrader5。python--versionPython3.11.0pip--versionpip22.3.1pipinstallMetaTrader5ERROR:CouldnotfindaversionthatsatisfiestherequirementMetaTrader5(fromversions:none)ERROR:Nomatchingdistribu......
  • C++11(2): 通用
    31.继承构造函数structB:A{usingA::A;};32.委派构造函数classA{public: A() :A(1234){}//先调用A(int) A(intn1):A(n1,'C'){}//先调用A(int,char) A(charc1):A(2,c1){}//先调用A(int,char)private: A(intn2,charc2):my_......
  • 【嵌入式DIY实例-ESP8266篇】-LCD ST7789显示DHT11传感器数据
    LCDST7789显示DHT11传感器数据文章目录LCDST7789显示DHT11传感器数据1、硬件准备与接线2、代码实现本文介绍如何将ESP8266NodeMCU板(ESP-12E)与DHT11(RHT01)数字湿度和温度传感器连接。NodeMCU从DHT11传感器读取温度和湿度值,并在ST7789TFT......
  • 时间序列分析方法汇总对比及优缺点和适用情况(下)-- 11. 卡尔曼滤波 12. 广义自回归条件
    目录11.卡尔曼滤波(KalmanFilter)12.广义自回归条件异方差模型(GARCH)13.贝叶斯结构时间序列模型(BayesianStructuralTimeSeries,BSTS)14.动态因子模型(DynamicFactorModel,DFM)15.隐马尔科夫模型(HiddenMarkovModel,HMM)16.分段线性回归(PiecewiseLinearRegress......
  • 【C++11】lambda表达式
    目录lambda表达式function包装器bind绑定lambda表达式我们之前如果要对一组数据排序,我们可以调用sort,并且传一个仿函数对象或者函数指针或者调用库中的类模板并实例化成对象,比如:boolLess(inta,intb){ returna<b;}structGreater{ booloperator()(inta......