当前位置:网站首页>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
边栏推荐
- Utility function---string processing
- Oracle RAC环境下vip/public/private IP的区别
- router---模式
- 2042. 检查句子中的数字是否递增-力扣双百代码-设置前置数据
- 工具函数---字符串处理
- 节省50%成本!京东云重磅发布新一代混合CDN产品
- Execution failed for task ‘:xxx:generateReleaseRFile‘.
- 第四讲 SVN
- Map常见的遍历方式-keySet 和 entrySet
- "Social Enterprises Conducting Civilian Personnel Training Specifications" group standard on the shelves of Xinhua Bookstore
猜你喜欢
汉诺塔怎么玩
理论篇1:深度学习之----LetNet模型详解
【牛客刷题-SQL大厂面试真题】NO5.某宝店铺分析(电商模式)
开放麒麟 openKylin 版本规划敲定:10 月发布 0.9 版并开启公测,12 月发布 1.0 版
【模型部署与业务落地】基于量化芯片的损失分析
Is there a replacement for the LM2596?LM2576 can
nVisual secondary development - Chapter 2 nVisual API operation guide Swagger use
How to stress the MySQL performance indicators TPS\QPS\IOPS?
This article sorts out the development of the main models of NLP
将 Sentinel 熔断限流规则持久化到 Nacos 配置中心
随机推荐
MySQL性能指标TPS\QPS\IOPS如何压测?
九州云出席领航者线上论坛,共话5G MEC边缘计算现状、挑战和未来
CCF GLCC正式开营|九州云开源专家携丰厚奖金,助力高校开源推广
浙江大学团队使用基于知识图谱的新方法,从空间分辨转录组数据中推断细胞间通信状况
js深拷贝和浅拷贝具体使用区别_es6深拷贝和浅拷贝
理论篇1:深度学习之----LetNet模型详解
国家安全机关对涉嫌危害国家安全犯罪嫌疑人杨智渊实施刑事拘传审查
Rust 从入门到精通04-变量
GeoAO:一种快速的环境光遮蔽方案
router---编程式导航
南瓜科学产品升级 开启益智探索新篇章
SLAM 04.视觉里程计-1-相机模型
router---mode
Lecture 4 SVN
Fuse bit of AVR study notes
【牛客刷题-SQL大厂面试真题】NO5.某宝店铺分析(电商模式)
LM2596有没有可以替代的?LM2576可以
【无标题】
Interviewer: How to view files containing abc string in /etc directory?
考研上岸又转行软件测试,从5k到13k完美逆袭,杭州校区小哥哥拒绝平庸终圆梦!