CentOS7 安装 PostgreSQL

1.首先安装PostgreSQL的rpm

wget https://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

rpm -ivh pgdg-redhat-repo-latest.noarch.rpm

2. 安装PostgreSQL服务器

yum install postgresql11-server postgresql11-contrib

  • 11为安装11.x版 10为安装10.x版 96为安装9.6版

初始化数据库

/usr/pgsql-11/bin/postgresql-11-setup initdb

配置文件目录:/var/lib/pgsql/data

启动PostgreSQL

systemctl start postgresql-11

修改postgres用户密码,切换到postgres用户

sudo passwd postgres
su postgres

然后使用psql工具登录数据库,列出当前的数据库,命令分别是 psql 和 \l