dk pull citusdata/citus
# 启动数据库。账户名 pg ,密码 pg
docker run -d --name citus -p 5432:5432 -e POSTGRES_USER=pg -e POSTGRES_PASSWORD=pg citusdata/citus
see python code: ./db/
点击侧边栏 - 图标名 database (如果没有安装需要先在插件市场安装) - 在上方菜单栏点击 “+” Add connection - Server Type: PostgreSQL - Host 192.168.1.31 - Port 5432 - Username pg - Password pg - Database douyin - Save
# 查看版本号
pgcli -v
# 如果出错,需要安装依赖工具:pip install psycopg_binary
# see:https://github.com/dbcli/pgcli/issues/1413
# 进入数据库命令行, sv-v 是另一台内网主机的域名, 5432 端口, pg 是 PostgreSQL 用户名, douyin 是其中一个数据库
pgcli -h sv-v -p 5432 -U pg douyin
# 查看 pgcli 支持指令
\?
# 查看 SQL 指令
\h
# 查看当前数据库名称和用户名
\c
# 新建数据库
create database douyin
# 列出所有数据库
\l
# 退出命令行
quit
# 免密输入。设置环境变量
export PGPASSWORD=pg
# 此时访问数据库不再需要密码。 -l 是列出有多少个数据库
pgcli -h sv-v -p 5432 -U pg -l
db_params = {
'database_url': "postgresql://your_database_user:your_database_password@your_database_host:your_database_port/your_database_name"
}
engine = create_engine(db_params['database_url'])
SQLModel.metadata.create_all(engine)
PostgreSQL 官网: https://github.com/postgres/postgres ,github 地址:https://github.com/postgres/postgres
本项目使用的版本是 PostgreSQL 14.0 ,官方文档: https://www.postgresql.org/docs/14/index.html
Citus 是一个 PostgreSQL 插件,主要用户扩展、管理基于 PostgreSQL 的分布式集群。
Citus 官方文档: https://docs.citusdata.com/en/stable/installation/single_node_docker.html
Citus 官方仓库: https://github.com/citusdata/citus?tab=readme-ov-file
pgcli 是一个命令行工具,可以在Python环境中使用命令行操作 PostgreSQL 数据库。安装: pip install pgcli,