postgres

官网 | PostgreSQL 教程

Postgresql常用操作

PostgreSQL JOIN 多表查询

MVCC(多版本并发控制)

pgvector - git

pgvector 插件构建向量数据库并进行相似度查询

#导入数据
\i ~/test/cmd.sql

PostgreSQL 与 Supabase 的关系
Supabase 是一个开源数据基础设施平台,底层基于 PostgreSQL 数据库系统,提供云端数据库服务。其核心功能包括实时数据同步、多租户支持及地理空间分析,适用于企业级应用场景。 

PostgreSQL 与 DuckDB 的整合
pg_duckdb 是 PostgreSQL 的扩展插件,将 DuckDB 的列式存储和矢量化分析引擎集成到 PostgreSQL 中。该扩展允许用户直接在 PostgreSQL 中执行 DuckDB 的分析查询,并优化大规模数据处理的性能。
整合优势
  1 性能提升:DuckDB 的列式存储和矢量化计算能力可加速复杂数据分析查询,尤其适合处理超大规模数据集。
  2 兼容性:pg_duckdb 扩展支持 PostgreSQL 的标准类型系统,简化数据交互流程。
  
timescaleDB 时序数据库
时席数据库Timeu Series Database.TSDB)是专门为时序数据(按时间而席记录的数据点)设计的局效存储与香询数据库,它针对时序数据的高写入频率、时间相关性、时间范围查询频繁等特点进行了优化,广泛应用于物联网(0T四)、工业监控、DevOps监控、金融行情、气象数据等领域。

直接通过 PostgreSQL扩展安装(CREATE EXTENSION timescaledb;),适合小规模数据(亿级以下)或开发测试环境。

备份工具pg_dump和pg_resotre

\dt list tables of the public schema
\dt *.*
\dn list all schemas
\dt employees.*
select * from pg_catalog.pg_tables where schemaname='employees;

DROP SCHEMA Lab1 CASCADE;
CREATE SCHEMA Lab1;
CREATE TABLE Lab1.PERSONS(
  SSN   INT primary key,
  Name CHARACTER (30),
  HouseId  INT,
  ApartmentNumber  INT ,
  Salary   DECIMAL (5, 2)  
);
t=# \dt+ lab1.persons
 lab1   | persons | table | postgres | 0 bytes |

配置

su - postgres
#vim data/postgresql.conf
#设置可访问IP
listen_address = '*'

#vim data/pg_hba.conf
#设置可访问IP
host    all             all             0.0.0.0/0               md5

设置访问IP和访问模式md5
# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   all             portgres                                md5
local   all             all                                     md5
host    all             all             127.0.0.1/32            md5
host    all             all             0.0.0.0/0               md5
host    all             all             ::1/128                 md5
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

psql
\password postgres

psql -U postgres -h 127.0.0.1 -d jwedemo

root#vim ~/.pgpass
#host:port:database:username:password
localhost:5432:jwtdemo:postgres:password000

postgresql

sudo yum install postgresql postgresql-server -y
sudo postgresql-setup initdb
sudo systemctl enable postgresql
sudo systemctl start postgresql

sudo su postgres
#psql postgres
相当于下行命令:
sudo -u postgres psql postgres

sudo -i -u postgres
su - postgres

设置用户postgres密码
\password postgres

创建用户:
sudo -u postgres createuser username 

– List all the databases:
# \list
– Connect to a database:
# \c database_name
– List all the tables
# \d
- List a table
# \d jwtbase
- List installed plugins
# \dx
– Create a Database
# create database miniflux2;
# createdb database_name
# createdb database_name OWNER rolename;
– Create a table
# create table employees (name varchar(25), surname varchar(25));
– Insert records
# INSERT INTO employees VALUES ('Lotfi','waderni');
– Exit from PosgreSQL prompt:
# \q
#