当前位置:网站首页>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
边栏推荐
猜你喜欢

企业应当实施的5个云安全管理策略

Redis 复习计划 - Redis主从数据一致性和哨兵机制

【毕设选题推荐】机器人工程专业毕设选题推荐

Analysis and application of portrait segmentation technology

Execution failed for task ‘:xxx:generateReleaseRFile‘.

谁说 Mysql 单表最大 2000 W ?我硬要塞它 1 个亿

idea去掉spark的日志

干掉visio,这个画图神器真的绝了

牛客网刷题记录 || 链表

Interviewer: How to view files containing abc string in /etc directory?
随机推荐
将 Sentinel 熔断限流规则持久化到 Nacos 配置中心
错误 AttributeError type object 'Callable' has no attribute '_abc_registry' 解决方案
CCF GLCC正式开营|九州云开源专家携丰厚奖金,助力高校开源推广
idea永久激活教程(新版)
汉诺塔怎么玩
字符串类的设计与实现_C语言字符串编程题
七夕邂逅爱,那人一定在
爬虫——动作链、xpath、打码平台使用
"C pitfalls and pitfalls" reading summary
【牛客刷题-SQL大厂面试真题】NO5.某宝店铺分析(电商模式)
FreeConfig.h文件
Oracle RAC环境下vip/public/private IP的区别
SMART S7-200PLC串行自由口通讯(耐压测试仪)
如何在ubuntu环境下安装postgresql并配置远程访问
ssm学习心得(完结篇
Programmer Qixi Gift - How to quickly build an exclusive chat room for your girlfriend in 30 minutes
C# 动态加载卸载 DLL
Lecture 4 SVN
牛客网刷题记录 || 链表
TS - type