CentOS下pgAdmin使用教程汇总
pgAdmin是PostgreSQL的图形化管理工具,需先安装PostgreSQL作为后端数据库。
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(rpm -E %{rhel})-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql15-server postgresql15-devel
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb # 初始化数据库集群
sudo systemctl enable --now postgresql-15 # 开机启动并立即启动服务
postgres用户,执行SQL命令创建用户(如pgadmin)并授权:sudo -u postgres psql
CREATE USER pgadmin WITH PASSWORD 'YourStrongPassword123!' CREATEDB; # 创建用户并允许创建数据库
GRANT ALL PRIVILEGES ON DATABASE postgres TO pgadmin; # 授权访问默认数据库
\q # 退出psql
pgAdmin Web版更适合远程管理,以下是具体安装步骤:
sudo yum install -y pgadmin4-web
sudo /usr/pgadmin4/bin/pgadmin4-web-setup.sh
按提示输入管理员邮箱(如admin@yourdomain.com)和密码(如PgAdminAdmin@123)。sudo systemctl start pgadmin4 # 启动服务
sudo systemctl enable pgadmin4 # 开机自启动
pgAdmin Web版依赖Apache提供HTTP服务,需调整配置以允许外部访问:
sudo cp /etc/httpd/conf.d/pgadmin4.conf.sample /etc/httpd/conf.d/pgadmin4.conf
vi)打开配置文件,确认以下设置:
Listen localhost:80改为Listen 80;ServerName localhost改为服务器公网IP或域名(如ServerName pgadmin.yourdomain.com)。sudo systemctl restart httpd
若系统启用了firewalld,需开放HTTP(80端口)和PostgreSQL(5432端口):
sudo firewall-cmd --permanent --add-service=http # 开放HTTP服务
sudo firewall-cmd --permanent --add-port=5432/tcp # 开放PostgreSQL端口
sudo firewall-cmd --reload # 重新加载防火墙规则
http://your_server_ip),使用初始化时设置的管理员邮箱和密码登录。localhost,若远程连接则为PostgreSQL服务器IP)、端口(默认5432)、用户名(pgadmin,即步骤一中创建的用户)、密码(步骤一中设置的密码);/tmp)、格式(如Custom或Plain),点击“Start”开始备份;