Skip to content

PG DB

Install

docker

docker run --name postgresql-container -p 5432:5432 -e POSTGRES_PASSWORD=[password] -d postgres

PgAdmin

docker run --rm -p 5050:5050 thajeztah/pgadmin4

docker run --name pgadmin -d -p 5050:5050 thajeztah/pgadmin4

location: http:127.0.0.1:5000

忘记密码怎么办?

  1. goto pg_dba.conf: /etc/postgresql/13/main

  2. edit pg_hba.conf,将localhost 部分的peer修改为 trust.

  3. restart: service postgresql restart
  4. into: psql -U postgres
  5. Alter password: ALTER USER postgres WITH PASSWORD 'new_password';
  6. reback conf file, restart.

Commands

common

  1. 查询basic 信息。
# db
\l or \l+;
# table
\dt;

PG变化捕获

监听pg的业务数据库,当特定表数据变化,实时通知

  • 高频轮询
  • 日志CDC[变化捕获]
  • 触发器
  • pgsql-http
  • Listen-Notify(version>7.2)

SQL

  • SQL
-- 监听channelA频道
LISTEN channelA;

-- 向channelA广播消息
NOTIFY channelA, 'test-message';
  • pl/pgsql
-- 监听channelA频道
PERFORM pg_listen('channelA');

-- 向channelA广播消息
PERFORM pg_notify('channelA', 'test-message');

server

  • java
  • python
  • nodejs
  • golang
  • rust
  • c#

SSE(Server-Sent Events)

http://www.ruanyifeng.com/blog/2017/05/server-sent_events.html