Linux PostgreSQL离线下载与安装
这是我自己开发的一个关于小工具,感兴趣的可以了解下。打开微信扫描一下下面的二维码即可体验。(也可以微信搜索“找茬大闯关”“科目一驾照”)需要源码的可以联系我qq337882150。需要查看怎么创建数据库用户、怎么分配权限可以查看博主其他文章。先连上用户postgres、数据库postgres。切换用户\c-[user_name]->选择对应的版本对应的操作系统->PG数据库创建视图并授权给新用户。
Linux PostgreSQL离线下载与安装
1. 软件包说明
软件包 | 说明 |
---|---|
postgresql-client | libraries and client binaries |
postgresql-server | core database server |
postgresql-contrib | additional supplied modules |
postgresql-devel | libraries and headers for C language development |
2. 下载离线安装包
Direct RPM download -> direct download->选择对应的版本对应的操作系统 -> PostgreSQL Database Server 13 PGDG -> 下载离线安装包
3. 进行PostgresSQL的安装
[root@db-postgresql13 home]# rpm -ivh postgresql13-*
warning: postgresql13-13.3-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:postgresql13-libs-13.3-1PGDG.rhel################################# [ 25%]
2:postgresql13-13.3-1PGDG.rhel7 ################################# [ 50%]
3:postgresql13-server-13.3-1PGDG.rh################################# [ 75%]
4:postgresql13-contrib-13.3-1PGDG.r################################# [100%]
4. 初始化db
[root@db-postgresql13 home]# /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database ... OK
5. 启动PostgreSQL服务
[root@db-postgresql13 home]# systemctl start postgresql-13
# 查看服务状态
[root@db-postgresql13 ~]# systemctl status postgresql-13
● postgresql-13.service - PostgreSQL 13 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2021-06-22 10:58:04 CST; 13min ago
Docs: https://www.postgresql.org/docs/13/static/
Process: 13539 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 13545 (postmaster)
Tasks: 8
CGroup: /system.slice/postgresql-13.service
├─13545 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
├─13547 postgres: logger
├─13549 postgres: checkpointer
├─13550 postgres: background writer
├─13551 postgres: walwriter
├─13552 postgres: autovacuum launcher
├─13553 postgres: stats collector
└─13554 postgres: logical replication launcher
Jun 22 10:58:04 db-postgresql13 systemd[1]: Starting PostgreSQL 13 database server...
Jun 22 10:58:04 db-postgresql13 postmaster[13545]: 2021-06-22 10:58:04.147 CST [13545] LOG: redirecting log output to logging collector process
Jun 22 10:58:04 db-postgresql13 postmaster[13545]: 2021-06-22 10:58:04.147 CST [13545] HINT: Future log output will appear in directory "log".
Jun 22 10:58:04 db-postgresql13 systemd[1]: Started PostgreSQL 13 database server.
# 加入开机启动
[root@db-postgresql13 ~]# systemctl enable postgresql-13
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-13.service to /usr/lib/systemd/system/postgresql-13.service.
6. 进入PostgreSQL数据库
# 切换到postgres用户
[root@db-postgresql13 ~]# su - postgres
Last login: Tue Jun 22 11:13:17 CST 2021 on pts/1
# 查看postgresql版本
-bash-4.2$ psql --version
psql (PostgreSQL) 13.3
# 进入数据库
-bash-4.2$ psql
psql (13.3)
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. 【postgresql 】使用\c 命令切换数据库和用户切换数据库:\c [database_name]
切换用户:\c - [user_name]
先连上用户postgres、数据库postgres
$ su - postgres
Last login: Wed Mar 1 13:16:48 CST 2017 on pts/1
-bash-4.2$ psql
psql (9.2.18)
Type "help" for help.
postgres=#
切换数据库
postgres=# \c fyc_db;
You are now connected to database "fyc_db" as user "postgres".
fyc_db=#
切换用户
fyc_db=# \c - fyc_user;
Password for user fyc_user:
You are now connected to database "fyc_db" as user "fyc_user".
fyc_db=>
需要查看怎么创建数据库用户、怎么分配权限可以查看博主其他文章。
PG数据库创建视图并授权给新用户https://blog.csdn.net/fyc__iOS/article/details/120780704?spm=1001.2014.3001.5502
这是我自己开发的一个关于小工具,感兴趣的可以了解下。打开微信扫描一下下面的二维码即可体验。 (也可以微信搜索 “ 找茬大闯关 ” “科目一驾照”) 需要源码的可以联系我 qq:337882150
更多推荐
所有评论(0)