简单记录了一下自己学postgresql的过程,求收藏求点赞!!!
主要学习这几部分:部署及服务管理、用户及权限、Navicat连接数据库、SQL、性能调优、数据备份、集群搭建。
部署及服务管理、用户及权限、Navicat连接数据库、启动服务这几部分都比较简单
第一部分:PostgresSQL的安装
我使用centos7安装postgresql10具体过程:
安装rpm文件
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
安装客户端和服务端
yum install postgresql12
yum install postgresql12-server
执行完安装之后会创建一个postgresql-12
服务, 此时未进行数据库初始化, 还无法访问。会创建一个postgres
/postgres
的用户,密码相同。
初始化
/usr/pgsql-12/bin/postgresql-12-setup initdb
设置自动启动并且启动postgresql服务
systemctl enable postgresql-10
systemctl start postgresql-10
默认配置文件地址: /usr/lib/systemd/system/postgresql-12.service
如果cat
命令查看配置文件, 我们可以得到一些基础信息:数据库数据目录
: Environment=PGDATA=/var/lib/pgsql/12/data/
postgresql安装目录
: PGHOME=/usr/pgsql-12/
[root@localhost opt]# cat /usr/lib/systemd/system/postgresql-12.service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades. It is recommended to use systemd
# "dropin" feature; i.e. create file with suffix .conf under
# /etc/systemd/system/postgresql-12.service.d directory overriding the
# unit's defaults. You can also use "systemctl edit postgresql-12"
# Look at systemd.unit(5) manual page for more info.
# Note: changing PGDATA will typically require adjusting SELinux
# configuration as well.
# Note: do not use a PGDATA pathname containing spaces, or you will
# break postgresql-setup.
[Unit]
Description=PostgreSQL 12 database server
Documentation=https://www.postgresql.org/docs/12/static/
After=syslog.target
After=network.target
[Service]
Type=notif