我现在的用户是 pronto
mediapop_staging=> select current_user;
current_user
--------------
pronto
(1 row)
Run Code Online (Sandbox Code Playgroud)
此用户是在 AWS RDS 上创建的标准超级用户。
mediapop_staging=> \du pronto
List of roles
Role name | Attributes | Member of
-----------+-------------------------------+-----------------
pronto | Create role, Create DB +| {rds_superuser}
| Password valid until infinity |
Run Code Online (Sandbox Code Playgroud)
但我得到这个:
mediapop_staging=> REASSIGN OWNED BY pronto TO mediapop_staging;
ERROR: permission denied to reassign objects
Run Code Online (Sandbox Code Playgroud)
为什么?我该如何解决?
在 Void Linux 上运行 PostgreSQL 服务器。安装后initdb以操作系统用户“postgres”的身份运行:
[user@host]$ sudo -u postgres -i
$ initdb -D '/var/lib/postgresql/data'
Run Code Online (Sandbox Code Playgroud)
接收输出:
创建目录 /var/lib/postgresql/data ... ok 创建子目录 ... ok 选择默认 max_connections ... 100 选择默认 shared_buffers ... 128MB 选择动态共享内存实现 ... posix 创建配置文件 ... ok正在运行引导脚本... ok 执行 post-bootstrap 初始化 ... 语言环境:无法将 LC_MESSAGES 设置为默认语言环境:没有这样的文件或目录 ok 正在将数据同步到磁盘 ... 好的
警告:为本地连接启用“信任”身份验证您可以在下次运行 initdb 时通过编辑 pg_hba.conf 或使用选项 -A 或 --auth-local 和 --auth-host 来更改此设置。
成功。您现在可以使用以下命令启动数据库服务器: pg_ctl -D /var/lib/postgresql/data -l logfile start
然后我继续创建服务,将所有权授予“postgres”并启动它:
[user@host]$ ln -s /etc/sv/postgresql /var/service
[user@host]$ sudo chown postgres: …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚为什么我的表在索引扫描速度非常快时使用位图堆扫描。
桌子:
webarchive=# \d web_pages
Table "public.web_pages"
Column | Type | Modifiers
-------------------+-----------------------------+---------------------------------------------------------------------
id | bigint | not null default nextval('web_pages_id_seq'::regclass)
state | dlstate_enum | not null
errno | integer |
url | text | not null
starturl | text | not null
netloc | text | not null
file | bigint |
priority | integer | not null
distance | integer | not null
is_text | boolean |
limit_netloc | boolean |
title | citext |
mimetype | text …Run Code Online (Sandbox Code Playgroud) postgresql performance postgresql-9.6 postgresql-performance
我们想将我们的数据库从虚拟主机提供商 (postgres 9.0) 移动到我们的本地网络服务器(尝试了 postgres 10 和最新的 11)我们的机器是 windows 服务器,具有 16gb ram 的快速 XEON 机器,仅用于数据库。
但即使在提高 default_statistics_targer = 4000 并分析统计数据之后,我们也无法运行许多以前运行非常快的视图。似乎虚拟主机提供商的服务器经过了微调,我们的执行计划可能出于某种原因很奇怪。
我们的 Postgres 是库存安装配置。
简化的示例查询如下(最大的表是“dale 表,它有几百万条记录大(它是带有外键的绑定表)其他表要小得多,一万条记录(系统是真空分析的,它是全新安装的)
EXPLAIN ANALYZE
SELECT REKLAMACNY_LIST.ID REKLAMACNY_LIST_ID
FROM REKLAMACNY_LIST
WHERE REKLAMACNY_LIST.VALIDTO IS NULL
AND
( SELECT NOT tr.typ_odstupenia::boolean
AND sr.konecny_stav::boolean
FROM dale d1
CROSS JOIN typ_reklamacie tr
CROSS JOIN dale d2
CROSS JOIN stav_reklamacie sr
WHERE TRUE
AND d1.fk7 = reklamacny_list.id
AND d2.fk7 = reklamacny_list.id
AND d1.fk1 = tr.id
AND d2.fk3 = sr.id
AND sr.validto IS NULL …Run Code Online (Sandbox Code Playgroud) 使用Amazon Aurora Postgres 2.0 版,它基本上是带有修改过的存储层的 PostgreSQL 10.4。
尝试恢复包含多行的转储,如:
ALTER FUNCTION myschema.f_myfunc(anyarray, anyelement) OWNER TO myrole;
Run Code Online (Sandbox Code Playgroud)
我收到每一个ALTER FUNCTION这样的错误消息:
Run Code Online (Sandbox Code Playgroud)ERROR: improper qualified name (too many dotted names)
在 psql 中尝试相同的方法会产生相同的错误。即使是最简单的形式:
ALTER FUNCTION foo() OWNER TO myrole;
Run Code Online (Sandbox Code Playgroud)
没有点名。我在这里发现了类似的抱怨:https : //forums.aws.amazon.com/thread.jspa?messageID=872096&tstart=0
一定是 Aurora 中的错误 - 还是我遗漏了什么?
通过以下查询,我可以使用 LAG() 函数重复列的最后一个非空值c:
SELECT coalesce(open_time, extract(EPOCH from date_trunc('minute', datetime)) * 1000) open_time,
coalesce(o, LAG(c) over w) o,
coalesce(h, LAG(c) over w) h,
coalesce(l, LAG(c) over w) l,
coalesce(c, LAG(c) over w) c,
coalesce(v, 0) v,
coalesce(close_time, extract(EPOCH from date_trunc('minute', datetime)) * 1000 + ((60000 * 1) - 1)) close_time
from temporary_timeframe
window w as (order by datetime);
Run Code Online (Sandbox Code Playgroud)
得到以下结果:
但是我需要c在当前列值为空时重复列的值。我看到如果 PostgreSQL 支持IGNORE NULLS窗口函数的属性,这将得到解决。如何解决这个没有IGNORE NULLS?
我Enum在编程语言级别有一个 an ,它作为一个简单的整数存储在表上。思考:
APPLE = 1
GOOGLE = 2
MSFT = 3
AMAZON = 4
... (100s more)
Run Code Online (Sandbox Code Playgroud)
我只想查询表而不是数字返回相应的字符串值。在不使用case语句或临时表的情况下,是否有更简单的方法来执行此操作:
SELECT
CASE WHEN type = 1 THEN "APPLE"
CASE WHEN type = 2 THEN "GOOGLE"
CASE WHEN type = 3 THEN "MSFT"
CASE WHEN type = 4 THEN "AMAZON"
...
ELSE "UNKNOWN"
FROM t
Run Code Online (Sandbox Code Playgroud)
基本上它只是在字典中进行键查找。
我想知道斜线|/在做什么,
SET equal_area_radius = |/area/pi();
Run Code Online (Sandbox Code Playgroud)
该语句有效,它肯定会更改值:
SELECT |/125.555/pi(); -- returns: 6.32181918120139
SELECT 125.555/pi(); -- returns: 39.9653977598058
Run Code Online (Sandbox Code Playgroud)
斜线运算符有|/什么作用?
这只是在 Reddit 上的一个问题中提出的,我想知道
PARTITIONED OUTER JOIN甲骨文中的a是什么?(定义)PARTITIONED OUTER JOIN?(等价)我对 postgres 的 wiki 页面中提到的数据库复制方法之间的差异感到困惑,哪种最适合正常情况?
热备份/连续归档/日志传送
提供高可用性
http://www.postgresql.org/docs/current/static/warm-standby.html
热备/二进制复制/流复制
用于只读查询
https://wiki.postgresql.org/wiki/Hot_Standby
https://wiki.postgresql.org/wiki/Binary_Replication_Tutorial
PITR
postgresql ×10
performance ×2
amazon-rds ×1
aws-aurora ×1
case ×1
installation ×1
join ×1
linux ×1
operator ×1
oracle ×1
query ×1
replication ×1
terminology ×1