Posgresql macOS安装和基础操作

摘要

本文介绍macOS版本Postgresql的安装,pg常用命令。作为笔记记录,后续方便查看。

Postgresql安装

官网下载postgresql安装包https://www.postgresql.org/download/。官网下载慢时,可以从这里下载我上传的mac版本的pg安装包资源。下载后,直接双击按照提示安装即可。

Postgresql常见操作命令

查看配置文件位置

bash 复制代码
show config_file;
#输出为:Users/***/Library/Application Support/Postgres/var-12/

数据库启动停止命令

bash 复制代码
# 启动数据库
service postgresql start
# 重启服务
service  postgresql  restart
# 停止服务
service  postgresql  stop
# 服务状态
service  postgresql  status

创建用户以及授予权限

bash 复制代码
# 登录超级用户
sudo -u postgres psql
# 创建用户并分配权限
CREATE USER <username> WITH PASSWORD '<password>';
ALTER USER myuser WITH CREATEDB; -- 分配创建数据库的权限
ALTER USER myuser WITH LOGIN; -- 允许用户登录

查看用户、DB、端口等信息

bash 复制代码
# 切换用户, 修改密码
alter user postgres with password '1234';

#查看端口号
SELECT setting FROM pg_settings WHERE name = 'port';

# 创建DB
create database psdb;

# 查看所有用户
select * from pg_roles;

#列出所有DB
\l; 

#连接db
\c dbname; 

连接数据库出现:Ident 认证失败

连接数据库出现psql: 致命错误: 用户 "postgres" Ident 认证失败。引起该问题的直接原因是密码错误,其次是pg配置问题。需要修改pg的配置文件,将method修改为trust。该文件位于PostgreSQL数据目录中,并且它控制哪些用户可以从哪些位置连接到哪些数据库。

METHOD字段值为trust可以通过用户名密码连接

bash 复制代码
TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             127.0.0.1/32            trust

数据库连接工具

  • vscode中postgresql插件(PostgreSQLv6.9.10-publisher:"Weijan Chen")
  • dbeaver
相关推荐
周小董2 小时前
[1369]Windows上安装PostgreSQL
数据库·windows·postgresql
OliverQiu6 小时前
开源一个 macOS 小工具:集中管理 ChatGPT 的网络启动配置
macos·chatgpt·swiftui·mac·proxy·codex·dmg
ss27311 小时前
03 -AI时代首先数据库-PostgreSQL发展历史:从伯克利到AI数据库
postgresql
东风微鸣14 小时前
精简 Ubuntu Linux 固件包:每个 N100 节点省下约 450 MB
linux·ubuntu·postgresql
wangDer_me15 小时前
将mac电脑变成一个虚拟打印机
macos·电脑
加载力科技1 天前
Mac 打开 ISO 文件完整教程:3 种方法挂载与解压,挂载失败也能提取文件
macos·命令模式·磁盘工具·mac打开iso·hdiutil·iso解压·mac技巧
Web Security Loop1 天前
MAC安装最新Burpsuite pro详细步骤教程
web安全·macos·网络安全·安全性测试
yumgpkpm1 天前
CDP 7.3.1(Cloudera Runtime 7.3.1)VS Acceldata ODP 3.3.6.4 核心引擎详细版本对比
大数据·hive·hadoop·postgresql·zookeeper·spark·hbase
明日清晨1 天前
mobaxterm root身份登录Ubuntu
linux·ubuntu·postgresql
Raspberry_Pi_官方账号1 天前
Raspberry Pi Desktop 全面升级,现已登陆 PC 和 Mac
服务器·网络·macos·树莓派·raspberry pi·raspberrypios