如何在Fedora 33/32/31/30上安装PostgreSQL 11
本教程用于在Fedora 33/32/31/30上安装PostgreSQL 11.
PostgreSQL是一个强大的开源关系数据库系统,可靠性,具有强大的可靠性,功能鲁棒性和性能。
关键PostgreSQL 11增强功能:
分区功能的改进,支持嵌入的交易到并行性的交易管理程序的过程现在支持SQL:2011 Standardoptional即时(JIT)编译中所示的所有帧选项,用于一些SQL代码,加快对表现形式改进的评估,包括避免的能力表格重写用于alter table ...添加具有非空列的列,现在可以使用Create Index的include子句创建一个非空列DefaultCovering索引
使用以下步骤在Fedora 33/32/31/30/29系统上安装PostgreSQL 11.
fedora存储库和模块化存储库上可用的默认版本为10.x
第1步:更新系统
确保系统包是最新的:
sudo dnf install -y bash-completion vim sudo dnf update -y
由于我们可能有内核更新,因此建议在升级后重新启动系统
sudo reboot
第2步:添加PostgreSQL yum存储库
通过运行以下命令将PostgreSQL yum存储库添加到Fedora系统:Fedora 33:
sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-33-x86_64/pgdg-fedora-repo-latest.noarch.rpm
Fedora 32:
sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-32-x86_64/pgdg-fedora-repo-latest.noarch.rpm
Fedora 31:
sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-31-x86_64/pgdg-fedora-repo-latest.noarch.rpm
Fedora 30:
https://download.postgresql.org/pub/repos/yum/reporpms/F-30-x86_64/pgdg-fedora-repo-latest.noarch.rpm
对于Fedora 29:
sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-29-x86_64/pgdg-fedora-repo-latest.noarch.rpm
提示确认安装时,按Y键。
................................... Dependencies resolved. ================================================================================ Package Architecture Version Repository Size ================================================================================ Installing: pgdg-fedora-repo noarch 42.0-4 @commandline 9.6 k Transaction Summary ================================================================================ Install 1 Package Total size: 9.6 k Installed size: 9.1 k Is this ok [y/N]: y Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : pgdg-fedora-repo-42.0-4.noarch 1/1 Verifying : pgdg-fedora-repo-42.0-4.noarch 1/1 Installed: pgdg-fedora-repo-42.0-4.noarch Complete!
第3步:安装PostgreSQL服务器和客户端包
添加PostgreSQL yum存储库后,安装PostgreSQL Server/Client Package:
$sudo dnf install postgresql11-server postgresql11 PostgreSQL 11 30 - x86_64 22 kB/s | 138 kB 00:06 PostgreSQL 10 30 - x86_64 18 kB/s | 130 kB 00:07 PostgreSQL 9.6 30 - x86_64 16 kB/s | 128 kB 00:07 PostgreSQL 9.5 30 - x86_64 20 kB/s | 120 kB 00:06 PostgreSQL 9.4 30 - x86_64 16 kB/s | 111 kB 00:06 Last metadata expiration check: 0:00:01 ago on Mon 06 Jan 2019 10:47:09 AM EAT. Dependencies resolved. ===================================================================================================================================================================================================== Package Architecture Version Repository Size ===================================================================================================================================================================================================== Installing: postgresql11 x86_64 11.2-2PGDG.f30 pgdg11 1.7 M postgresql11-server x86_64 11.2-2PGDG.f30 pgdg11 4.9 M Installing dependencies: postgresql11-libs x86_64 11.2-2PGDG.f30 pgdg11 375 k Transaction Summary ===================================================================================================================================================================================================== Install 3 Packages Total download size: 6.9 M Installed size: 32 M Is this ok [y/N]: y Downloading Packages: (1/3): postgresql11-libs-11.2-2PGDG.f30.x86_64.rpm 75 kB/s | 375 kB 00:05 (2/3): postgresql11-11.2-2PGDG.f30.x86_64.rpm 274 kB/s | 1.7 MB 00:06 (3/3): postgresql11-server-11.2-2PGDG.f30.x86_64.rpm 208 kB/s | 4.9 MB 00:23 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 296 kB/s | 6.9 MB 00:23 warning: /var/cache/dnf/pgdg11-cde8ad453ae6cd5b/packages/postgresql11-11.2-2PGDG.f30.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY PostgreSQL 11 30 - x86_64 1.6 MB/s | 1.7 kB 00:00 Importing GPG key 0x442DF0F8: Userid : "PostgreSQL RPM Building Project <Hyman@theitroad>" Fingerprint: 68C9 E2B9 1A37 D136 FE74 D176 1F16 D2E1 442D F0F8 From : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG Is this ok [y/N]: y Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : postgresql11-libs-11.2-2PGDG.f30.x86_64 1/3 Running scriptlet: postgresql11-libs-11.2-2PGDG.f30.x86_64 1/3 Installing : postgresql11-11.2-2PGDG.f30.x86_64 2/3 Running scriptlet: postgresql11-11.2-2PGDG.f30.x86_64 2/3 Running scriptlet: postgresql11-server-11.2-2PGDG.f30.x86_64 3/3 Installing : postgresql11-server-11.2-2PGDG.f30.x86_64 3/3 Running scriptlet: postgresql11-server-11.2-2PGDG.f30.x86_64 3/3 Verifying : postgresql11-11.2-2PGDG.f30.x86_64 1/3 Verifying : postgresql11-libs-11.2-2PGDG.f30.x86_64 2/3 Verifying : postgresql11-server-11.2-2PGDG.f30.x86_64 3/3 Installed: postgresql11-11.2-2PGDG.f30.x86_64 postgresql11-server-11.2-2PGDG.f30.x86_64 postgresql11-libs-11.2-2PGDG.f30.x86_64 Complete!
确认已安装的包:
$rpm -qi postgresql11-server Name : postgresql11-server Version : 11.2 Release : 2PGDG.f30 Architecture: x86_64 Install Date: Mon 06 Jan 2019 10:49:47 AM EAT Group : Applications/Databases Size : 21514298 License : PostgreSQL Signature : DSA/SHA1, Mon 01 Apr 2019 08:32:00 PM EAT, Key ID 1f16d2e1442df0f8 Source RPM : postgresql11-11.2-2PGDG.f30.src.rpm Build Date : Mon 01 Apr 2019 08:31:35 PM EAT Build Host : koji-fedora30-x86-64-pgbuild Relocations : (not relocatable) Vendor : PostgreSQL Global Development Group URL : https://www.postgresql.org/ Summary : The programs needed to create and run a PostgreSQL server Description : PostgreSQL is an advanced Object-Relational database management system (DBMS). The postgresql11-server package contains the programs needed to create and run a PostgreSQL server, which will in turn allow you to create and maintain PostgreSQL databases.
第4步:初始化数据库并启用自动启动
既然已经安装了数据库包,通过运行以下命令初始化数据库
$sudo /usr/pgsql-11/bin/postgresql-11-setup initdb Initializing database ... OK
然后启动并启用服务开始启动
sudo systemctl start postgresql-11 sudo systemctl enable postgresql-11
确认服务状态。
$sudo systemctl status postgresql-11 ● postgresql-11.service - PostgreSQL 11 database server Loaded: loaded (/usr/lib/systemd/system/postgresql-11.service; disabled; vendor preset: disabled) Active: active (running) since Mon 2019-05-06 10:52:19 EAT; 30s ago Docs: https://www.postgresql.org/docs/11/static/ Process: 12779 ExecStartPre=/usr/pgsql-11/bin/postgresql-11-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS) Main PID: 12784 (postmaster) Tasks: 8 (limit: 2323) Memory: 15.7M CGroup: /system.slice/postgresql-11.service ├─12784 /usr/pgsql-11/bin/postmaster -D /var/lib/pgsql/11/data/ ├─12785 postgres: logger ├─12787 postgres: checkpointer ├─12788 postgres: background writer ├─12789 postgres: walwriter ├─12790 postgres: autovacuum launcher ├─12791 postgres: stats collector └─12792 postgres: logical replication launcher Jan 06 10:52:19 myregistry.local systemd[1]: Starting PostgreSQL 11 database server... Jan 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.739 EAT [12784] LOG: listening on IPv6 address "::1", port 5432 Jan 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.740 EAT [12784] LOG: listening on IPv4 address "127.0.0.1", port 5432 Jan 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.742 EAT [12784] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" Jan 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.743 EAT [12784] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432" Jan 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.752 EAT [12784] LOG: redirecting log output to logging collector process Jan 06 10:52:19 myregistry.local postmaster[12784]: 2019-05-06 10:52:19.752 EAT [12784] HINT: Future log output will appear in directory "log". Jan 06 10:52:19 myregistry.local systemd[1]: Started PostgreSQL 11 database server.
postgreSQL 11配置文件是 /var/lib/pgsql/11/data/postgresql.conf
如果我们有运行防火墙服务和远程客户端应连接到数据库服务器,请允许PostgreSQL服务。
sudo firewall-cmd --add-service=postgresql --permanent sudo firewall-cmd --reload
第5步:为PostgreSQL启用远程Acess
编辑文件 /var/lib/pgsql/11/data/postgresql.conf
并将所有接口的Server IP地址或者"*"侦听收听地址。
listen_addresses = '*'
还将PostgreSQL设置为接受远程连接
$sudo vim /var/lib/pgsql/11/data/pg_hba.conf # Accept from anywhere host all all 0.0.0.0/0 md5 # Accept from trusted subnet host all all 192.168.18.0/24 md5
重启服务
sudo systemctl restart postgresql-11
第6步:设置PostgreSQL管理员用户的密码
设置PostgreSQL管理员用户
$sudo su - postgres [Hyman@theitroad ~]$psql -c "alter user postgres with password 'StrongPassword'" ALTER ROLE
创建测试用户和数据库
[Hyman@theitroad ~]$createuser test_user [Hyman@theitroad ~]$createdb test_db -O test_user [Hyman@theitroad ~]$grant all privileges on database test_db to test_user;
以A登录 test_user
用户尝试在数据库上创建一个表。
$psql -U test_user -h localhost -d test_db
第7步:安装pgadmin 4
在CentOS 7/Fedora上安装PGAdmin 4,以从Web界面管理PostgreSQL。