在学习一项新技能之前,必先利其器,也就是需要先懂得如何安装PostgreSQL数据库。这里记录下在Centos7.6 安装PostgreSQL数据库,版本10.1的过程,以下步骤紧凑:
可以从postgreSQL源网址下载安装yum源,点击https://yum.postgresql.org/repopackages.php#pg10
选择centos7-x86 64,右键选择复制链接,然后在系统终端执行以下命令,更新yum源:
yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm -y
可以通过下面命令,在终端查看刚刚安装的postgresql源的rpm包,然后来安装对应版本的postgresql。
yum list | grep postgresql
执行以下命令安装postgreSQL数据库的server:
yum install postgresql10-contrib postgresql10-server -y
Postgresql安装目录在/usr/pgsql-10,而Postgresql的数据目录会放在/var/lib/pgsql/版本号/data目录下
可以通过运行命令,来查看PostgreSQL 的命令帮助 :
/usr/pgsql-10/bin/postgresql-10-setup --help
可以看到,initdb参数可以用以初始化数据库:
然后运行:
/usr/pgsql-10/bin/postgresql-10-setup initdb
可以看到以下显示,则为安装并初始化成功:
sudo systemctl start postgresql-10
sudo systemctl enable postgresql-10.service
这是由于可能系统中安装过PostgreSQL数据库,然后同样IP下的端口被占用了,需要卸载掉之前的PostgreSQL rpm包,然后重新启动即可。卸载命令:
yum remove postgresql
postgresql在安装时默认会添加用户postgres,可以通过以下命令进入数据并设置密码:
su - postgres #切换到postgres用户下 psql #登陆数据库
ln -s /usr/pgsql-10/bin/psql /usr/bin/psql
执行完上述步骤,应该可以看到如下的画面,则证明数据库登陆成功:
执行以下命令:
ALTER USER postgres WITH PASSWORD <password>;
其中password是你要设置的密码,如下所示:
至此在Centos7上安装postgreSQL数据库基本实现,下面大家可以专心学习如何使用postgreSQL数据库了,祝大家学习愉快~
PostgreSQL 学习01 Centos7.6安装PostgreSQL10
原文:https://www.cnblogs.com/Crise2018/p/11568328.html