文章 / 数据与中间件 / postgresql 入门

postgresql 入门

postgresql的部署和权限

2025年4月29日2 min598 words
postgresql 入门
图 1-1 cover.webp

安装

apt install postgresql

连接

一. 切换用户 postgres 的默认账号是postgres 但是无法直接通过控制台登录

sudo -i -u postgres
pgsql

二. 修改登录方式

# 14是当前的版本号
# 修改 /etc/postgresql/14/main/pg_hba.conf
# 修改前
# local   all             postgres                peer
# 修改后
local   all             postgres                 trust

重启postgresql服务 此时可以直接登录

psql -U postgres
# 登录后设置密码
alter user postgres with password '你的密码';

修改/etc/postgresql/14/main/pg_hba.conf

local   all             postgres                peer

并保存。 此时可以通过密码登录

psql -U postgres -h localhost -d postgres

三. 创建新用户

create user xxx with pawword 'xxx';
create role;

创建数据库

一. 创建数据库

create database xx owner xxx;

二 赋予用户数据库权限

GRANT ALL PRIVILEGES ON DATABASE xxx TO xx;

评论 (0)

加载评论中...
RELATED NOTES
05 entries
01n8n 技术实践(三):自托管、扩展、安全与可观测性阅读文章 →02n8n 技术实践(二):把 Webhook 与 API 工作流做成生产级阅读文章 →03docker镜像资源阅读文章 →04mcp服务的node实现阅读文章 →05kafka阅读文章 →