我有这个查询,我想开始工作。我试图在某个非空的日期之后计算外键的所有实例,然后将其与原始表的不同之处连接起来,这样我就可以看到没有条目的变量。这是我的查询:
select fulllist.fk_fc_id
from
(
select distinct fk_fc_id
from data_item
) as fulllist
left outer join
(
select temp.fk_fc_id, count(*) as number
from
(
select *
from data_item
where di_item_value not like 'Null'
and di_timestamp > '2013-11-01 00:00:00'
) as temp
group by fk_fc_id
) as lj
on lj.fc_fk_id=fulllist.fk_fc_id;
Run Code Online (Sandbox Code Playgroud)
错误是
错误:列 lj.fc_fk_id 不存在
第 19 行:在 lj.fc_fk_id=fulllist.fk_fc_id 上;
我有 2 个 HD 分区 - 一个带有 SSD,另一个带有普通硬盘。
我有多个数据库(如逻辑数据库,而不是物理数据库)和 1 个数据目录。我希望 1 个数据库的数据驻留在 SSD 分区中,因为它是一个比其他数据库具有更多读/写的数据库。而且由于 SSD 分区的空间有限,我无法将所有数据库存储在那里,仅存储一个。
有没有办法在 Postgres 中配置它 - 有可能吗?有在线教程可以阅读吗?我试过谷歌搜索,但所有的结果都在讨论逻辑分区表,而不是跨不同的硬盘分区。
我收到错误ERROR: permission denied for relation users并尝试使用两者更新权限
grant all privileges on all tables in schema ops to my_user
GRANT ALL PRIVILEGES ON TABLE the_table TO my_user
在DBVisualizer中我的资助选项卡可以看到my_user用户拥有的权限DELETE,INSERT,SELECT,TRUNCATE,和UPDATE。 IS_GRANTABLE所有这些都设置为 NO。但是我仍然收到此错误。还剩下什么。
我正在做数据库清理以释放postgreSQL数据库的磁盘空间。相应的桌子尺寸很大,需要很长时间才能完成吸尘。但不幸的是,由于网络连接缓慢,网络连接终止,导致吸尘在中间终止。
我担心是否会发生任何数据库损坏。我可以再次发出数据库真空命令吗?
vacuum full message_log;
请说清楚。
我最近开始研究PostgreSQL,我有大约1200 万行要处理,我想在其中应用Full Text Search。我之前没有处理此类数据库的任何经验。我已尝试优化查询,但我怀疑它是否已完全优化。
现在我正在使用GIST 索引,因为我读到GIN 索引中的更新速度较慢,并且我的数据库将定期更新。
我现在只需要关注数据库的两列merchant varchar(80)和product varchar(400).
我需要使用 FTS 查找产品,并且即使商家拼写错误,我也正在尝试获取该产品。
我在大约30K行的示例数据库上运行了一些查询,以获得以下结果:
首先,我运行基本的 FTS 查询来分析结果。
explain analyze
select count(*) from products
where to_tsvector('english', product) @@ to_tsquery('hat');
Run Code Online (Sandbox Code Playgroud)Run Code Online (Sandbox Code Playgroud)Aggregate (cost=2027.27..2027.28 rows=1 width=0) (actual time=349.032..349.032 rows=1 loops=1) -> Seq Scan on products (cost=0.00..2026.90 rows=147 width=0) (actual time=43.322..348.961 rows=307 loops=1) Filter: (to_tsvector((product)::text) @@ to_tsquery('hat'::text)) Total runtime: 349.140 ms
然后我创建了 GIST 索引并运行相同的查询以查看改进。结果非常好。至少对于我来说。
create index product_gist on products …Run Code Online (Sandbox Code Playgroud)postgresql index optimization full-text-search pattern-matching
我正在编写一个 PL/pgSQL 函数,它为我需要检查它是否返回某些内容的查询创建一个游标。
我正在做的是这样的:
我发现,检查,如果该查询返回的东西用光标是最好的选择,因为它(加入5个表和大量列)一个很长的查询和SELECT ... INTO不正确的顺心,因为我必须创建一个TYPE自查询具有来自一个表的列和用于距离计算的列。
问题是我目前仅使用游标来检查查询是否在我打开和关闭它的循环中返回了某些内容。一旦查询返回某些内容,我就退出循环并返回查询。我可以马上说,这是我需要的丑陋的解决方法。也许有人可以帮助我解决这个问题。
这是一些显示我目前正在做的事情的代码。
CREATE FUNCTION store_distance(
latitude double precision,
longitude double precision,
radius double precision,
tries integer
)
RETURNS TABLE(
store_id store.id%type,
store_name store.name%type,
distance double precision
)
AS
$$
DECLARE
cur_stores CURSOR FOR
SELECT
store.id,
store.name,
get_distance(latitude, longitude, store.latitude, store.longitude) distance
FROM
store
WHERE
store.latitude BETWEEN (latitude - radius) AND (latitude + radius)
AND store.longitude BETWEEN (longitude - radius) AND (longitude + radius)
ORDER BY …Run Code Online (Sandbox Code Playgroud) PostgesSQL 9.3.x
我无法在从站上运行某些命令,因为:“错误:恢复正在进行中”
我设置了没有存档的流媒体。用 pg_basebackup 初始化。数据集大约有 180GB 。这是我在查看相关进程时得到的奴隶:
23378 ? Ss 0:12 postgres: startup process recovering 000000010000026000000083
23379 ? Ss 0:02 postgres: checkpointer process
23380 ? Ss 0:00 postgres: writer process
23382 ? Ss 0:00 postgres: stats collector process
23383 ? Ss 0:14 postgres: wal receiver process streaming 260/837D8000
Run Code Online (Sandbox Code Playgroud)
字节滞后(在主机上查询)在 0 到 2000 字节之间。
recovery.conf 内容:
standby_mode = 'on'
primary_conninfo = 'host=SOME_IP port=5432 user=postgres sslmode=require'
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
\d 聚合
Materialized view "public.aggregate"
Column | Type | Modifiers
------------------+-----------------------------+-----------
id | integer |
searchable | text |
name | character varying(255) |
source_type | character varying(255) |
source_id | integer |
latitude | double precision |
longitude | double precision |
created_at | timestamp without time zone |
updated_at | timestamp without time zone |
Indexes:
"aggregate_lat_lng_point" gist (point(latitude, longitude))
"searchable_tsvector" gin (to_tsvector('english'::regconfig, COALESCE(searchable, ''::text)))
Run Code Online (Sandbox Code Playgroud)
询问:
EXPLAIN ANALYZE SELECT name FROM aggregate
WHERE point(53.574753, -2.1) <@> point(latitude, longitude) …Run Code Online (Sandbox Code Playgroud) pg_restore: [archiver] did not find magic string in file header当我pg_restore -Fc -U "username" -d "dbname" "filename".dmp在临时数据库上执行 a 时,我不断收到此信息。
这些数据库在两个单独的 AWS 实例上运行,Windows Server 2008 用于两种环境(暂存和分发)。发行版中使用的 postgres 版本是 9.2,登台版本是 9.3。
我认为这个问题可能与pg_dump: [custom archiver] WARNING: ftell mismatch with expected position -- ftell used我pg_dump -Fc -U "username" -w "dbname" > "filename".dmp在分发数据库上执行 a 时收到几个警告的事实有关。
任何帮助表示赞赏。
我在 Postgres 9.3.3 中有一个大约 700k 行的表,它具有以下结构:
Columns:
content_body - text
publish_date - timestamp without time zone
published - boolean
Indexes:
"articles_pkey" PRIMARY KEY, btree (id)
"article_text_gin" gin (article_text)
"articles_publish_date_id_index" btree (publish_date DESC NULLS LAST, id DESC)
Run Code Online (Sandbox Code Playgroud)
我所做的查询有全文搜索查询和限制,如下所示:
当我在我的索引中搜索具有限制和顺序的字符串时,查询速度很快:
explain analyze select * from "articles" where article_text @@ plainto_tsquery('pg_catalog.simple', 'in_index') order by id limit 10;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.42..1293.88 rows=10 width=1298) (actual time=2.073..9.837 rows=10 loops=1)
-> Index Scan using articles_pkey on articles (cost=0.42..462150.49 rows=3573 width=1298) (actual time=2.055..9.711 rows=10 loops=1)
Filter: …Run Code Online (Sandbox Code Playgroud) postgresql ×10
index ×2
performance ×2
optimization ×1
partitioning ×1
permissions ×1
php ×1
plpgsql ×1
spatial ×1