安装包下载地址:
https://www.enterprisedb.com/download-postgresql-binaries
1.创建用户
[root@node03 ~]# useradd postgres
[root@node03 ~]# echo "postgres " | passwd --stdin postgres
Changing password for user postgres.
passwd: all authentication tokens updated successfully.
[root@node03 ~]# id postgres
uid=54323(postgres) gid=54331(postgres) groups=54331(postgres)
2.创建目录
[root@node03 ~]# mkdir -p /software/postgres
[root@node03 ~]# mkdir -p /postgres/pgsql_data
[root@node03 ~]# chown -R postgres.postgres /software/*
[root@node03 ~]# chown -R postgres.postgres /postgres/*
3.上传postgresql安装包并解压
[root@node03 ~]# su - postgres
[postgres@node03 ~]$
[postgres@node03 ~]$ cd /software/postgres
[postgres@node03 postgres]$ ll
total 158776
-rw-r--r-- 1 postgres postgres 162584327 Nov 23 18:55 postgresql-10.23-1-linux-x64-binaries.tar.gz
[postgres@node03 postgres]$
[postgres@node03 postgres]$ tar -xvf postgresql-10.23-1-linux-x64-binaries.tar.gz
4.初始化
[postgres@node03 postgres]$ /software/postgres/pgsql/bin/initdb -D /postgres/pgsql_data/
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /postgres/pgsql_data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... PRC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/software/postgres/pgsql/bin/pg_ctl -D /postgres/pgsql_data/ -l logfile start
[postgres@node03 postgres]$
5.启动数据库
[postgres@node03 postgres]$ /software/postgres/pgsql/bin/pg_ctl -D /postgres/pgsql_data/ -l logfile start
waiting for server to start.... done
server started
[postgres@node03 postgres]$
6.登陆数据库
[postgres@node03 postgres]$ /software/postgres/pgsql/bin/psql -Upostgres -dpostgres
psql.bin (10.23)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
postgres=#
7.关闭数据库
[postgres@node03 postgres]$ /software/postgres/pgsql/bin/pg_ctl -D /postgres/pgsql_data/ -l logfile stop
waiting for server to shut down.... done
server stopped
[postgres@node03 postgres]$
8.扩展
postgres=# \l ----------列出所有的database
postgres=# \c test ----------选择database
test=# \d ----------列出所用database的表
test=# \d tablename ----------查看表结构
test=# \q ----------退出登陆