这篇文章主要是为了指导新用户如何在 Ubuntu Linux 系统上安装 pgAdmin 4。pgAdmin 是一个功能丰富的开源 PostgreSQL 管理和开发平台,可在 Linux、Unix、Mac OS X 和 Windows 上运行。
使用 pgAdmin,您可以使用直观且功能强大的 Web 界面管理 PostgreSQL 数据库服务器(从版本 9.2 开始)。
如果您运行的是 Ubuntu 系统或 Linux Mint,本文将适合您。
在 Ubuntu 上安装 pgAdmin4 的一个要求是 PostgreSQL 服务器。您可以选择使用任何版本的 PostgreSQL 服务器 >=9.6。
在 Ubuntu 上完成 PostgreSQL 数据库服务器的安装后,继续在系统上安装并启动 pgAdmin4。
1.添加 pgAdmin4 存储库
所有基于 Debian 的 Linux 操作系统的 pgAdmin 软件包均可从 pgAdmin APT 存储库获取。在此步骤中,我们将存储库添加到我们的 Ubuntu 系统。
curl -fsSL https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/pgadmin.gpg
使用下一个命令在您的 Ubuntu 系统中添加pgAdmin存储库:
sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list'
您可以使用以下命令检查创建的存储库文件的内容:
$ cat /etc/apt/sources.list.d/pgadmin4.list
deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/bullseye pgadmin4 main
2. 在 Ubuntu 上安装 pgAdmin4
最后,更新包列表。
sudo apt update
要在 Ubuntu 系统上安装 pgAdmin4 包,请运行以下命令并提供正确的版本号:
sudo apt install pgadmin4
按y键继续在 Ubuntu 上安装pgAdmin4。
....
cpp-doc gcc-9-locales libdigest-hmac-perl libgssapi-perl libcrypt-ssleay-perl lm-sensors libauthen-ntlm-perl libunicode-map8-perl libunicode-string-perl xml-twig-tools postgresql-12
postgresql-doc-12 mesa-utils nickle cairo-5c xorg-docs-core
The following NEW packages will be installed:
cpp cpp-9 fontconfig-config fonts-dejavu-core gcc-9-base libapache2-mod-wsgi-py3 libatomic1 libauthen-sasl-perl libdata-dump-perl libdrm-amdgpu1 libdrm-intel1 libdrm-nouveau2 libdrm-radeon1
libencode-locale-perl libfile-basedir-perl libfile-desktopentry-perl libfile-listing-perl libfile-mimeinfo-perl libfont-afm-perl libfontconfig1 libfontenc1 libgl1 libgl1-mesa-dri libglapi-mesa
libglvnd0 libglx-mesa0 libglx0 libhtml-form-perl libhtml-format-perl libhtml-parser-perl libhtml-tagset-perl libhtml-tree-perl libhttp-cookies-perl libhttp-daemon-perl libhttp-date-perl
libhttp-message-perl libhttp-negotiate-perl libice6 libio-html-perl libio-socket-ssl-perl libio-stringy-perl libipc-system-simple-perl libisl22 libllvm12 liblwp-mediatypes-perl
liblwp-protocol-https-perl libmailtools-perl libmpc3 libnet-dbus-perl libnet-http-perl libnet-smtp-ssl-perl libnet-ssleay-perl libpciaccess0 libpq5 libsensors-config libsensors5 libsm6
libtie-ixhash-perl libtimedate-perl libtry-tiny-perl liburi-perl libvulkan1 libwayland-client0 libwww-perl libwww-robotrules-perl libx11-protocol-perl libx11-xcb1 libxaw7 libxcb-dri2-0
libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-randr0 libxcb-shape0 libxcb-shm0 libxcb-sync1 libxcb-xfixes0 libxcomposite1 libxcursor1 libxfixes3 libxft2 libxi6 libxinerama1 libxkbfile1
libxml-parser-perl libxml-twig-perl libxml-xpathengine-perl libxmu6 libxpm4 libxrandr2 libxrender1 libxshmfence1 libxt6 libxtst6 libxv1 libxxf86dga1 libxxf86vm1 mesa-vulkan-drivers
perl-openssl-defaults pgadmin4 pgadmin4-desktop pgadmin4-server pgadmin4-web postgresql-client postgresql-client-12 postgresql-client-common x11-common x11-utils x11-xserver-utils xdg-utils
0 upgraded, 110 newly installed, 0 to remove and 6 not upgraded.
Need to get 222 MB of archives.
After this operation, 508 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
安装后应该已经启动 Apache 服务。
systemctl status apache2
3. 为 pgAdmin4 配置 Apache Web 服务器
启动 Apache Web 服务器配置。
sudo /usr/pgadmin4/bin/setup-web.sh
这将要求您输入 pgadmin4 用户电子邮件地址并设置密码:
Setting up pgAdmin 4 in web mode on a Debian based platform...
Creating configuration database...
NOTE: Configuring authentication for SERVER mode.
Enter the email address and password to use for the initial pgAdmin user account:
Email address: <input-email-address>
Password: <input-password>
Retype password: <Reenter-password>
pgAdmin 4 - Application Initialisation
======================================
Creating storage and log directories...
同意 Apache Web 服务器的配置。
We can now configure the Apache Web server for you. This involves enabling the wsgi module and configuring the pgAdmin 4 application to mount at /pgadmin4. Do you wish to continue (y/n)? y
The Apache web server is running and must be restarted for the pgAdmin 4 installation to complete. Continue (y/n)? y
Apache successfully restarted. You can now start using pgAdmin 4 in web mode at http://127.0.0.1/pgadmin4
4. 访问 pgAdmin 4 Web 界面
如果您配置了 UFW 防火墙,请允许 http 和 https 流量。
sudo ufw allow http && sudo ufw allow https
打开浏览器并。http://[ServerIP_or_domain]/pgadmin4
使用设置的电子邮件地址和密码登录。
等待几秒钟以完成初始化。
在 pgAdmin 的第一页,点击 “添加新服务器”,添加一个 PostgreSQL 服务器,以便使用 pgAdmin 进行管理。 这可以是本地或远程 PostgreSQL 服务器。
在“常规” 部分下 ,为服务器提供名称和描述。
在“连接” 选项卡下 ,提供访问详细信息 - DB 主机、DB 用户和密码。
完成后,点击 保存 按钮保存配置。如果成功添加服务器,名称将显示在左侧边栏中。
选择服务器以查看数据库摘要信息并进行更改。从文档页面了解有关如何使用 pgAdmin 的更多信息。
如果您喜欢此文章,请收藏、点赞、评论,谢谢,祝您快乐每一天。