PGSQL
xcagy
CAGY官方博客
展开
-
pgsql给单独数据库制定账号权限
或其他PostgreSQL客户端,以具有足够权限的账号(如。这通常是通过赋予其CONNECT权限来实现的。数据库中所有表的读写权限。替换为你的安全密码。原创 2024-06-18 14:52:33 · 488 阅读 · 0 评论 -
postgrest的https配置ssl
【代码】postgrest的https配置ssl。原创 2023-08-07 14:17:48 · 127 阅读 · 0 评论 -
PGSQL设置数据库只读,表空间只读
-将schema中usage权限赋予给readonly用户,访问所有已存在的表。--将schema中表的查询权限赋予给readonly用户,访问所有已存在的表。--设置用户默认开启只读事务。--设置用户登录权限。原创 2023-04-20 12:39:57 · 700 阅读 · 1 评论 -
PostgreSQL 日志跟踪
当 log_statement=all 和 log_min_duration_statement 同时设置时,将跟踪所有语句,忽略log_min_duration_statement 设置。log_min_duration_statement = 5000 #milliseconds,记录执行5秒及以上的语句。log_rotation_size = 10240 #kb,文件多大后创建新的文件记录日志。log_statement = all #需设置跟踪所有语句,否则只能跟踪出错信息。原创 2023-01-14 14:46:21 · 1202 阅读 · 0 评论 -
PGSQL自动清理限制链接idle
PGSQL自动清理限制链接原创 2023-01-04 09:26:03 · 796 阅读 · 0 评论 -
PGSQL容器内执行SQL语句
root@xxxx:/usr/lib/postgresql/12/bin# ./psql -U postgres -h 127.0.0.1 数据库名。原创 2022-11-14 16:22:51 · 577 阅读 · 0 评论 -
PGSQL断开某个数据库的链接
select pg_terminate_backend(pid) from pg_stat_activity where datname='数据库名称';原创 2022-11-01 11:06:46 · 595 阅读 · 0 评论 -
PGSQL前后行合并为数组排序取最大最小值
【代码】PGSQL前后行合并为数组排序取最大最小值。原创 2022-09-29 15:40:09 · 790 阅读 · 0 评论 -
使用pg_dump备份数据库的命令
pg_dump -h 127.0.0.1 -p 5432 -U postgres -F c -b -v -f 备份文件名 数据库名称。原创 2022-08-29 12:32:03 · 523 阅读 · 0 评论 -
PGSQL查询所有表的字符串
PGSQL查询所有表的字符串原创 2022-07-20 17:27:23 · 318 阅读 · 0 评论 -
PGSQL插入或者更新的语法
insert into ads_oa_xxx_history (month, not_repair,avg_repair_tm)一个查询语句 ON conflict(month) DO UPDATE SET not_repair = excluded.not_repair,avg_repair_tm=excluded.avg_repair_tm原创 2022-07-09 09:28:10 · 1122 阅读 · 0 评论 -
postgrest简单用法
配置文件:db-uri = "postgres://postgres:密码@127.0.0.1:5432/dbname"db-schema = "public"db-anon-role = "postgres"db-pool = 10server-port = 4000启动服务./postgrest pgnohup ./postgrest pg&原创 2022-04-26 14:37:40 · 231 阅读 · 0 评论 -
查询PGSQL的每个表的大小
SELECT relname, age(relfrozenxid) as xid_age, pg_size_pretty(pg_table_size(oid)) as table_size FROM pg_class WHERE relkind = 'r' ORDER BY pg_table_size(oid) DESC LIMIT 20;原创 2022-01-19 16:37:37 · 1411 阅读 · 0 评论 -
PGSQL查询用户密码的MD5值
select rolpassword from pg_authid where rolname='postgres';原创 2021-11-11 10:40:53 · 792 阅读 · 0 评论 -
三条命令docker安装pgpool2、pgsql
docker run --detach --rm -p 5432:5432 --name pg-0 \ --network my-network \ --env REPMGR_PARTNER_NODES=pg-0,pg-1 \ --env REPMGR_NODE_NAME=pg-0 \ --env REPMGR_NODE_NETWORK_NAME=pg-0 \ --env REPMGR_PRIMARY_HOST=pg-0 \ --env REPMGR_PASSWORD=repm...原创 2021-11-05 14:11:18 · 1028 阅读 · 0 评论 -
PGSQL创建管理员账号
create user uuuuu password 'dddddd' superuser createrole createdbgrant postgres to uuuuu原创 2021-10-28 16:33:46 · 872 阅读 · 0 评论 -
PGSQL字符串截取与替换
select * from qa limit 10;update qa set an=replace(an,'";','')select split_part(c ,'****', 1),split_part(c ,'****', 2) from qa limit 100update qa set an=split_part(c ,'****', 2)原创 2021-10-21 17:09:27 · 6766 阅读 · 0 评论 -
pgpool-II读写分离
IP 角色 端口 192.168.0.31 master 5432 pgpool-II 9999 192.168.0.32 slave 5432一、基础环境配置 host设置修改名称,如果在下面的配置中无法使用主机名称,则使用IP地址 hostnamectl set-hostname masterhostnamectl set-hostname slave192.168.0.31 master192.168.0.32 slave原创 2021-09-05 10:45:18 · 618 阅读 · 0 评论 -
nginx用TCP转发HTTP
stream { upstream socket_proxy { hash $remote_addr consistent; server 127.0.0.1:80 weight=5 max_fails=3 fail_timeout=120s; } server { listen 8069; proxy_connect_timeout 2s; proxy_timeout 5s; proxy_pa...原创 2021-08-25 10:29:35 · 1182 阅读 · 0 评论 -
PGSQL修改在使用中的数据库名称
SELECT pg_terminate_backend(pg_stat_activity.pid)FROM pg_stat_activityWHERE datname='hot' AND pid<>pg_backend_pid();alter database hot rename to hot_predict;原创 2021-09-05 10:40:12 · 903 阅读 · 0 评论 -
PGSQL分组取最新
SELECT * FROM ( SELECT id,ip, row_number() over (partition by ip order by tm desc),cpu_use,disk_use,net_in FROM hw_info) AS de_dump WHERE row_number = 1ip地址是分组依据,tm字段是排序依据,别的字段随便写原创 2021-07-01 15:55:27 · 967 阅读 · 2 评论 -
全国最完整的Repmgr高可用Postgresql
标题应该没有违反广告法本教程为全国最完整的PGSQL高可用集群方案,以下的每一个步骤都事关重要。安装环境Centos7.8Posgresql10Repmgr10两台服务器:192.168.126.143192.168.126.144服务器名称:hostnamectl set-hostname post1hostnamectl set-hostname post2数据库集群架构图整体设计思路1.先两台机器都安装Posgresql2.两台机器都安装原创 2021-06-28 21:53:32 · 949 阅读 · 1 评论 -
快速启动docker pgsql-10
docker run -d -e POSTGRES_USER=odo -e POSTGRES_PASSWORD=odo -p 5432:5432 -e POSTGRES_DB=postgres --name db registry.cn-chengdu.aliyuncs.com/bjmaster/funenc-home-pgsql:v1.1原创 2021-01-25 21:23:32 · 170 阅读 · 0 评论 -
PGSQL计算14天均线
select(lag(shou,1) over(order by id)+lag(shou,2) over(order by id)+lag(shou,3) over(order by id)+lag(shou,4) over(order by id)+lag(shou,5) over(order by id)+lag(shou,6) over(order by id)+lag(shou,7) over(order by id)+lag(shou,8) over(order...原创 2021-01-24 22:11:25 · 263 阅读 · 0 评论 -
PGSQL获取所有表结构
selectcol.table_name as 表名,col.column_name as 字段名,col.data_type as 字段类型,des.description as 字段描述frominformation_schema.columns col left join pg_description des oncol.table_name::regclass = des.objoidand col.ordinal_position = des.objsubidwheretabl原创 2020-09-23 17:30:31 · 1416 阅读 · 0 评论 -
win10 安装postgrest并启动的教程
1.直接打开powershell2.输入Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')# or shorteriwr -useb get.scoop.sh | iex3.等安装完成新建一个d:\pst.txt,里面输入数据库链接的内容db-uri = "postgres://postgres:你的密码@127.0.0.1:5432/数据名字"原创 2020-09-20 17:37:32 · 884 阅读 · 2 评论 -
PGSQL新增用户授权的秘籍
首先用高级权限账号查出所有的表名字然后navicat新建用户新增权限,授予权限,然后发现每个表单独授权,太麻烦于是用下面的SQL获取所有表select distinctcol.table_name as 表名frominformation_schema.columns col left join pg_description des oncol.table_name::regclass = des.objoidand col.ordinal_position = des.objs原创 2020-08-26 15:54:34 · 856 阅读 · 0 评论 -
PGSQL循环语句FOR每一条记录,PGSQL循环每一行
CREATE OR REPLACE FUNCTION tuomin() RETURNS VOIDAS$$DECLARE t_row RECORD;BEGIN FOR t_row in (SELECT * FROM userx) LOOP update userx set usr ='xxx'; END LOOP;END;$$LANGUAGE plpgsql;SELECT tuomin() as output;...原创 2020-08-25 16:00:32 · 4295 阅读 · 0 评论 -
PGSQL 错行,上下行,前后行计算
错两行select lag(name,-2,'乱七八糟的空替换字符串') over(order by id) as las,* from sgdd错行更新当前字段的值update sgdd set name=z.las from(select lag(name,-2,'乱七八糟的空替换字符串') over(order by id) as las,* from sgdd) z where z.id=sgdd.id这个语句之宝贵啊我搜了好久才回忆起来...原创 2020-08-25 15:58:31 · 823 阅读 · 0 评论 -
PGSQL生成Restful接口
header:Prefer:resolution=merge-duplicates{"id":1,"user":"tct","pwd":"5201"}http://127.0.0.1:56456/bi_user?on_conflict=id原创 2020-08-21 15:11:47 · 595 阅读 · 0 评论 -
PGSQL去重取最新
select a.*,to_date(to_char(a.update_tm,'YYYY-01-01'),'YYYY-01-01') as 年份from(select department,name,indicators_num,occurrences_num,update_tm,(select max(write_date) from plan_repair_operational_indicators_info) as max_date from plan_repair_operationa原创 2020-08-07 16:50:54 · 1446 阅读 · 0 评论 -
PGSQL数据DATA目录迁移到别的机器
首先还是找一个全新的centos7的电脑去https://www.enterprisedb.com/download-postgresql-binaries下周linux 的压缩包然后二进制安装步骤:groupadd postgresuseradd -g postgres postgresid postgrespasswd postgresmkdir -p /data/postgresql/datamkdir -p /data/postgresql/log...原创 2020-08-05 10:23:59 · 588 阅读 · 0 评论 -
PGSQL计算每月延期天数
该SQL可以实现一条记录变成多条记录比如项目计划开始时间 1月1日,项目实际开始时间 4月1日,则会产生4条数据,1月延期31天,2月延期 28天,3 月延期31天4月延期1天select p.name as 项目名称,a.*,case when a.计划开始月份=a.实际开始月份 then date_part('day', cast(a.实际开始 as TIMESTAMP)- cast(a.计划开始 as TIMESTAMP)) when ...原创 2020-06-21 16:11:44 · 411 阅读 · 0 评论 -
win10安装pgsql 压缩包
解压zip到C盘在C:\pgsql下面data文件夹#初始化数据库 initdb.exe -D C:\pgsql\data -E UTF-8 --locale=chs -U postgres -W-D :指定数据库簇的存储目录E:\pgsql\data-E :指定DB的超级用户的用户名postgres--locale:关于区域设置(chinese-simplified-china)-U :默认编码格式chs-W :为超级用户指定密码的提示#pg数据库bin路径下C:\pgsq转载 2020-05-27 10:20:20 · 399 阅读 · 0 评论 -
PGSQL分组累加SQL
select *,(select sum(planmoney) as pl from table as inn where project_id = table.project_id and inn.date <= table.date) as plan_total,(select sum(actualmoney) as act from table as inn where proje...原创 2020-04-26 14:51:23 · 2229 阅读 · 0 评论 -
PGSQL触发器实例
---创建触发器执行的函数CREATE OR replace FUNCTION tri_assets_in_update()returns trigger as $$beginIF (new.total_invt-OLD.total_invt) > 0THEN insert into assets_in(code,ast_id,in_number,name,property...原创 2020-02-05 11:10:04 · 775 阅读 · 0 评论 -
PGSQL 10 安装后密码错误的解决办法-PGSQL10 安装方法
su - postgres 切换用户psql -U postgres 登录数据库,执行后提示符变为 ‘postgres=#’ALTER USER postgres WITH PASSWORD ‘****************’ 设置postgres用户密码二进制安装步骤:groupadd postgresuseradd -g postgres postgresid ...原创 2019-09-18 17:16:49 · 1575 阅读 · 0 评论 -
PGSQL创建自增主键字段
DROP SEQUENCE if EXISTS "public"."hrcount_id_seq";CREATE SEQUENCE "public"."hrcount_id_seq"INCREMENT 1MINVALUE 1MAXVALUE 9223372036854775807START 1CACHE 1;ALTER SEQUENCE hrcount_id_seq RESTART...原创 2019-10-16 16:30:52 · 819 阅读 · 0 评论 -
KETTLE前后行动态计算
1.先用SQL查询获得累加的字段2.利用KETTLE 统计里面的 分析查询功能 将值的字段错位3.然后利用KETTLE 计算器里面的字段相互加减乘除原创 2018-12-12 14:38:22 · 1367 阅读 · 0 评论 -
PGSQL获取年月 很重要
SELECT TO_CHAR(now(), 'yyyy-mm');PGSQL很难用。。。原创 2018-12-06 14:29:56 · 10217 阅读 · 0 评论