当前位置:网站首页>How to install postgresql and configure remote access in ubuntu environment
How to install postgresql and configure remote access in ubuntu environment
2022-08-04 14:04:00 【theskylife】
1.更新ubuntu包
sudo apt-get update
sudo apt-get upgrade
2.安装官方源
# 创建文件存储库配置
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# 导入存储库签名密钥
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# 更新包列表
sudo apt-get update
# 安装最新版本的PostgreSQL
sudo apt-get -y install postgresql
以上命令成功运行后,证明postgresql已经正常安装,It will start automatically after the installation is completepostgresql的服务.It can be viewed through the following informationpostgresql的信息
# 查看postgresql版本
sudo -u postgres psql -c "SELECT version();"
# 查看postgresql服务是否启动
service postgresql status
3.进行数据库配置
3.1 创建用户账号密码
在ubuntu上PostgreSQL数据库以后,A computer user is automatically createdpostgre,The following operations are based on this account.
运行以下命令,使用postgre用户登录postgresql
# 切换用户
sudo su postgres
# 进入交互界面
psql
进行postgresqlafter the interactive interface,User creation can be done by running the following information
-- Create an account without a password-root
create role root;
-- Create an account with a password-root
create user root with 'root123';
-- 显示所有用户,并查看是否创建成功
\du
-- 更改postgresql密码,如修改root账号的密码
alter user root with password 'root123#';
3.2 创建数据库
-- 创建数据库(test)
create database test;
-- 删除数据库(test)
drop database test;
-- 查询所有数据库
\l
-- 切换数据库test
\c test
3.3 创建schema
-- 创建schema(ods),以下写法均可
create schema ods;
create schema if not exists ods;
-- 为某个用户(root2)创建market
create schema market authorization roo2;
-- 查看当前数据库下的所有schema
select * from information_schema.schemata;
-- 删除schema(ods)
drop schema if exists ods;
3.4 用户权限授权
After creating the user password,Permissions can be granted to users with the following commands
-- 给用户root赋予超级用户权限
alter user root with superuser;
-- 给用户root2Grant ordinary permissions
alter user root2 with privileges;
-- Give all permissions to the database to the userroot
grant all privileges on database test to root;
-- 把某schema下(ods)的所有表(test用户下)All permissions are given to the userroot2
grant all on all tables in schema ods to root2;
-- put a table(test_table)All permissions are given to the userroot2
grant all on test_table to root2;
-- put a table(test_table)The query permission is given to the userroot2
grant select on table test_table to root2;
-- 撤销用户root2的某个数据库(test)权限;
revoke all on database test from root2;
-- 撤销用户root2某个schema(ods)Modifications to all tables below(update)权限;
revoke update on all tables in schema ods from root2;
-- 撤销用户root2某张表(test_table)的所有权限
revoke privileges on test_table from root2;
-- put a table(test_table)given by the ownerroot2
alter table test_table owner to root2;
-- 允许用户(root)登录
ALTER ROLE root WITH LOGIN;
-- 禁止用户(root)登录
ALTER ROLE root WITH NOLOGIN;
3.5 配置远程访问
由于postgresqlA username is added by default during installationpostgres的ubuntu系统用户,So you need to delete it with another account firstpostgres用户的密码,Then configure your own password.
# 删除postgres用户的密码
sudo passwd -d postgres
# 设置postgres用户的密码
sudo -u postgres passwd
After configuring the password,编辑/etc/postgresq/12/main/postgresql.conf文件
sudo vim /etc/postgresql/12/main/postgresql.conf
in the above configuration filepostgresql.conf中添加以下内容:
listen_addresses = '*'
password_encryption = scram-sha-256
运行以下命令,编辑/etc/postgresq/12/main/pg_hba.conf文件
sudo vim /etc/postgresql/14/main/pg_hba.conf
在pg_hba.conf文件末尾追加以下内容:
host all all 0.0.0.0/0 scram-sha-256
添加完成后,保存退出,然后重启postgresql 服务.
sudo service postgresql restart
3.6使用Navicat链接
Use the information obtained above,成功链接postgresql数据库.
3.7 卸载Navicat
# 移除postgresql
sudo apt-get --purge remove postgresql\*
# 移除配置信息
sudo rm -r /etc/postgresql/
sudo rm -r /etc/postgresql-common/
sudo rm -r /var/lib/postgresql/
sudo userdel -r postgres
sudo groupdel postgres
边栏推荐
猜你喜欢

封装、继承、多态的联合使用实现不同等级学生分数信息的统计

MySQL性能指标TPS\QPS\IOPS如何压测?

ICML 2022 | 图神经网络的局部增强

用过Apifox这个API接口工具后,确实感觉postman有点鸡肋......

【牛客刷题-SQL大厂面试真题】NO5.某宝店铺分析(电商模式)

nVisual二次开发——第二章 nVisual API操作指南Swagger使用

砺夏行动|九州云章津楠:开源不是少数人的运动,大众化才是源泉

SLAM 04.视觉里程计-1-相机模型

解题-->在线OJ(十八)

Execution failed for task ‘:xxx:generateReleaseRFile‘.
随机推荐
Execution failed for task ‘:xxx:generateReleaseRFile‘.
阴影初始化【5】
让Web页面中的编辑器支持黏贴或直接拖拽来添加图片「建议收藏」
c#之winform(软件开发)
编程思想_编程有必要给孩子学吗?
企业应当实施的5个云安全管理策略
Is there a replacement for the LM2596?LM2576 can
C# winforms 输入颜色转换颜色名
节省50%成本!京东云重磅发布新一代混合CDN产品
【LeetCode】38、外观数列
router---Programmatic navigation
国家安全机关对涉嫌危害国家安全犯罪嫌疑人杨智渊实施刑事拘传审查
eyb:JWT介绍
Redis 复习计划 - Redis主从数据一致性和哨兵机制
开放麒麟 openKylin 版本规划敲定:10 月发布 0.9 版并开启公测,12 月发布 1.0 版
七夕当然要学会SQL优化好早点下班去找对象
异步编程概览
第六届未来网络发展大会,即将开幕!
ssm学习心得(完结篇
MySQL【触发器】