PostgreSQL(通常称为Postgres)是一个功能强大、免费、开源、功能齐全、高度可扩展和跨平台的对象关系数据库系统,专为可靠性、功能稳健性和高性能而构建。
PostgreSQL可以在包括 Linux 在内的所有主要操作系统上运行。它使用并扩展了 SQL 语言,并结合了许多功能,可以安全地存储和扩展最复杂的数据工作负载。
PhpPgAdmin是一个用于通过网络管理PostgreSQL数据库的工具。它允许管理多个服务器,管理 PostgreSQL 的各个不同方面,并支持轻松的数据操作。
它还支持多种格式的表数据转储:SQL、COPY、XML、XHTML、CSV、Tabbed、pg_dump 以及导入 SQL 脚本、COPY 数据、XML、CSV 和 Tabbed。重要的是,它可以通过使用插件进行扩展。
在本文中,我们将介绍如何在openSUSE服务器版中安装PostgreSQL 10和PhpPgAdmin 5.6。
安装 PostgreSQL 数据库服务器
PostgreSQL 10可以使用以下zypper 命令从默认存储库安装在openSUSE上。
$ sudo zypper 安装 postgresql10-服务器 postgresql10
![](https://www.alaica.com/wp-content/uploads/linux-535.png)
安装过程完成后,启动Postgres服务,使其在系统启动时自动启动,并使用以下命令验证其状态。
$ sudo systemctl 启动 postgresql $ sudo systemctl 启用 postgresql $ sudo systemctl 状态 postgresql
![](https://www.alaica.com/wp-content/uploads/linux-536.png)
在安装过程中,Postgres"postgres"
会创建一个没有密码的管理数据库用户来管理PostgreSQL服务器。下一个重要步骤是通过为其设置密码来保护该用户帐户。
首先切换到postgres用户帐户,然后访问postgres shell 并为默认用户设置新密码,如下所示。
$ sudo su - postgres $psql # 密码 postgres
![](https://www.alaica.com/wp-content/uploads/linux-537.png)
配置 PostgreSQL 数据库服务器
此时,我们需要通过编辑客户端身份验证配置文件/var/lib/pgsql/data/pg_hba.conf来配置客户端对PostgreSQL服务器的访问。
$ sudo vim /var/lib/pgsql/data/pg_hba.conf
查找以下行并将身份验证方法更改为md5,如屏幕截图所示(请参阅官方PostgreSQL 10 文档以了解不同的身份验证方法)。
# "local" is for Unix domain socket connections only local all all md5 # IPv4 local connections: host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128 md5
![](https://www.alaica.com/wp-content/uploads/linux-538.png)
Then restart the postgres service for the changes to take effect.
$ sudo systemctl restart postgresql
Installing and Configuring PhpPgAdmin
As described earlier, phpPgAdmin is a web-based administration tool for PostgreSQL. By default, openSUSE has phpPgAdmin 5.1 which doesn’t support postgresql10. Therefore we need to install phpPgAdmin 5.6 as shown.
$ wget -c https://github.com/phppgadmin/phppgadmin/archive/REL_5-6-0.zip $ unzip REL_5-6-0.zip $ sudo mv phppgadmin-REL_5-6-0 /srv/www/htdocs/phpPgAdmin
After installing phpPgAdmin, you need to create the phpPgAdmin central configuration file from the provided sample file. Then open and edit the created file using your favorite text editor, for example:
$ cd /srv/www/htdocs/phpPgAdmin/conf/ $ cp config.inc.php-dist config.inc.php $ sudo vim config.inc.php
Then look for the line host configuration parameter and set its value to “localhost”
to enable TCP/IP connections on the localhost.
$conf['servers'][0]['host'] = 'localhost';
In addition, look for the extra login security parameter and change its value to from “true”
to “false”
to allow logins via phpPgAdmin using certain usernames such as pgsql, postgres, root, administrator:
$conf['extra_login_security'] = false;
Save the changes to the file and exit.
Next, enable Apache PHP and version modules required by phpPgAdmin and restart the Apache2 and postgresql services with the following commands.
$ sudo a2enmod php7 $ sudo a2enmod version $ sudo systemctl restart postgresql $ sudo systemctl restart apache2
Accessing PhpPgAdmin Dashboard
The final step is to access phpPgAdmin from a web browser and test connectivity to the database server. Use the address http://localhost/phpPgAdmin/
or http://SERVER_IP/phpPgAdmin/
to navigate.
The phpPgAdmin default interface should appear as shown. Click PostgreSQL to access the Login interface.
![](https://www.alaica.com/wp-content/uploads/linux-539.png)
At the login interface, enter the postgres as the usernames and provide the password you set earlier on for the default database user and click Login.
![](https://www.alaica.com/wp-content/uploads/linux-540.png)
![](https://www.alaica.com/wp-content/uploads/linux-541.png)
恭喜!您已在openSUSE中成功安装PostgreSQL 10和phpPgAdmin 5.6。如有任何问题或意见,请使用下面的反馈表。