分类 database 中的文章

Pgsql 时间加减

Pgsql 时间加减 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/02/01/pgsql-time-shift/ 时间管理 1 2 3 4 5 6 7 --时间加减 select now()+interval '1 year' ,now()+interval '-1 month' ,now()-interval '1 day' ,now()+interval '1 hour' ,100* interval '1 second' - 1*interval '1 minute';……

阅读全文

Pgsql 将数据移动到备份表

Pgsql 将数据移动到备份表 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/02/01/pgsql-move-data-to-another-table/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 -- -- 准备阶段, 删除表 drop table TABLE_Original; drop table TABLE_History; -- 创建 原始表, 模拟数据 create table TABLE_Original(ca varchar(10), createtime timestamp) insert into TABLE_Original(ca,createtime) values('r1','2024-03-10'); insert into TABLE_Original(ca,createtime) values('r1','2024-03-11'); insert into TABLE_Original(ca,createtime) values('r1','2024-03-12'); insert into TABLE_Original(ca,createtime) values('r1','2024-03-13'); -- 创建备份表 create table TABLE_History(ca varchar(10),createtime timestamp) -- -- 转移……

阅读全文

Pgsql Create Readonly Account

Pgsql Create Readonly Account 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2023/10/25/pgsql-create-readonly-account/ 授权 schema 只读权限 登陆到数据库 1 $ psql -u root -d dbname ; 切换到对应数据库 1 sql> \c dbname; 创建用户并授权 1 2 3 4 5 6 7 8 9 10 11 12 -- 创建用户 CREATE USER <USER_RO> WITH PASSWORD '<PASS_FOR_USER_RO>'; -- 授权 public schema 可以不用。 -- 授权非 public schema 需要保留。 GRANT USAGE ON SCHEMA <SCHEMA_NAME> TO <USER_RO>; -- 授权制度权限 GRANT SELECT ON ALL TABLES IN SCHEMA <SCHEMA_NAME> TO <USER_RO>; --授予将来新……

阅读全文

Aliyun RDS PostgreSQL权限管理最佳实践

Aliyun Rds Pgsql Permission Best Practise 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2023/07/14/aliyun-rds-pgsql-permission-best-practise/ 注意: 在 PgSQL 中, 用户是基于 实例 的, 权限是基于 数据表/数据库 的。 换句话说, 创建的用户是可以看见所有数据库和数据表的, 但是看不到其具体内容。 创建只读用户 0. 登陆/切换 目标数据库 直接登陆目标数据库 1 2 ## login psql -u root -d dbname ; 或者登陆后切换到目标……

阅读全文

Pgsql Stop Spliting Values in Mulitple Lines

Pgsql Stop Spliting Values in Mulitple Lines 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2023/07/13/pgsql-stop-spliting-values-in-mulitple-lines/ psql doesn’t split your string in multiple lines. It’s the string that contains new-line characters (ASCII 10), and psql displays them accurately. The + at the end of every line is psql’s way of telling you that the value is continued in the next line. You can use the unaligned mode (psql option -A) to get rid of the +, but the output format is less attractive then. You can get rid of the newlines in a string with 1 2 3 4 5 SELECT translate(..., E'\n', ''); # or SELECT REPLACE(..., E'\n', ''); decode will be able to handle such a string.……

阅读全文

Pgsql数据库: psql 命令非交互式备份与恢复

Pgsql数据库: psql 命令非交互式备份与恢复 通常, 我们在使用 psql 命令的时候, 使用交互式命令, 输入密码, 保证安全。 1 2 3 4 5 # 备份 pg_dump -U root -h 172.17.101.250 -W -d intelliep_event > demo.sql # 登录 psql -U root -h 172.17.101.250 -W -d intelliep_event < demo.sql 非交互式操作 但是在 脚本 中执行备份和恢复的时候, 交互式的输入密码就非常不方便了。 要实现非交互式, 非常简单。 只需要……

阅读全文

福利派送

  • (免费星球)「运维成长路线」

  • 又拍云免费 CDN

最近文章

分类

标签

其它