postgresql-9.1

Postgres query is very slow when using a parameter instead of an hardcoded string

耗尽温柔 提交于 2019-12-23 12:18:25
问题 I am running into this Postgres issue where the same query takes a long time to execute if I use a parameter vs hardcoding its value on the query string. The column name is 'media_type' and it's a VARCHAR(20). I am running these queries from PHP, using Symfony2 and Doctrine2 ORM and the table in question has about 1.000.000 records. Do I have a problem on my query? Can it be a Postgres configuration problem? 1 - Hardcoded value for media_type duration: 5.365 ms parse pdo_stmt_00000001: SELECT

Why is PostgreSQL (9.1) not using index for simple equality select?

喜夏-厌秋 提交于 2019-12-23 09:56:46
问题 My table lead has an index: \d lead ... Indexes: "lead_pkey" PRIMARY KEY, btree (id) "lead_account__c" btree (account__c) ... "lead_email" btree (email) "lead_id_prefix" btree (id text_pattern_ops) Why doesn't PG (9.1) use the index for this straightforward equality selection? Emails are almost all unique.... db=> explain select * from lead where email = 'blah'; QUERY PLAN ------------------------------------------------------------ Seq Scan on lead (cost=0.00..319599.38 rows=1 width=5108)

pg gem sslmode=verify-full, where to place certificates?

江枫思渺然 提交于 2019-12-23 02:21:11
问题 Is there a way for the pg-gem to use sslmode = verify-full for it's postgres connection? Would that be as simple as just passing that string in? I have a Rails app that I want to do full ca protected ssl connections on to an external db and I don't really know how to setup the ca part of that. Using require on sslmode defaults it to use ssl traffic but I don't know where (or under what user, etc.) I should be placing my certificates to do verification. Should I just place them under ~/

pg gem sslmode=verify-full, where to place certificates?

a 夏天 提交于 2019-12-23 02:20:49
问题 Is there a way for the pg-gem to use sslmode = verify-full for it's postgres connection? Would that be as simple as just passing that string in? I have a Rails app that I want to do full ca protected ssl connections on to an external db and I don't really know how to setup the ca part of that. Using require on sslmode defaults it to use ssl traffic but I don't know where (or under what user, etc.) I should be placing my certificates to do verification. Should I just place them under ~/

Variables for identifiers inside IF EXISTS in a plpgsql function

本小妞迷上赌 提交于 2019-12-22 13:08:52
问题 CREATE OR REPLACE FUNCTION drop_now() RETURNS void AS $BODY$ DECLARE row record; BEGIN RAISE INFO 'in'; FOR row IN select relname from pg_stat_user_tables WHERE schemaname='public' AND relname LIKE '%test%' LOOP IF EXISTS(SELECT row.relname.tm FROM row.relname WHERE row.relname.tm < current_timestamp - INTERVAL '90 minutes' LIMIT 1) THEN -- EXECUTE 'DROP TABLE ' || quote_ident(row.relname); RAISE INFO 'Dropped table: %', quote_ident(row.relname); END IF; END LOOP; END; $BODY$ LANGUAGE plpgsql

Changing ORDER BY from id to another indexed column (with low LIMIT) has a huge cost

ⅰ亾dé卋堺 提交于 2019-12-22 10:28:07
问题 I have a query on a 500 000 row table. Basically WHERE s3_.id = 287 ORDER BY m0_.id DESC LIMIT 25 => Query runtime = 20ms WHERE s3_.id = 287 ORDER BY m0_.created_at DESC LIMIT 25 => Query runtime = 15000ms or more There is an index on created_at. The Query plans are completely different. Unfortunately I am not a query plan guru. I would like to reproduce the fast query plan while ordering by created_at. Is that possible and how would I go about that ? Query Plan - Slow Query (order by m0_

Ordering differences between Postgres instances on different machines (same locale)

自闭症网瘾萝莉.ら 提交于 2019-12-22 09:04:10
问题 I have two Postgres 9.1 instances: one local, installed via Postgres.app on OS X, and one remote, on Heroku. I've ensured that lc_collate is en_US.UTF-8 on both machines but am still seeing different behavior between the two. On my local instance, SELECT 'i' > 'N' returns t whereas remotely it returns f . Given that I've already checked lc_* on both systems, what explains the difference I'm seeing? 回答1: From the point of view of Unicode, the case ordering is a customization. Excerpt from http

if a non-correlated subquery is repeated at several places in the query, can it be cached and the result reused?

99封情书 提交于 2019-12-22 07:03:14
问题 If I have a query like SELECT date_trunc('day', assigndate)e, count(CASE WHEN a.assigneeid = 65548 AND a.assigneeid IN (SELECT userid FROM groupmembers WHERE groupid = 65553) THEN 1 ELSE NULL END) assigned, count(CASE WHEN a.assigneeid = 65548 AND a.completedtime IS NOT NULL AND a.assigneeid IN (SELECT userid FROM groupmembers WHERE groupid = 65553) THEN 1 ELSE NULL END) completed FROM ASSIGNMENT a WHERE assigndate > CURRENT_TIMESTAMP - interval '20 days' GROUP BY date_trunc('day',assigndate)

Postgresql k-nearest neighbor (KNN) on multidimensional cube

瘦欲@ 提交于 2019-12-22 06:06:11
问题 I have a cube that has 8 dimensions. I want to do nearest neighbor matching. I'm totally new to postgresql. I read that 9.1 supports nearest neighbor matching on multidimensions. I'd really appreciate if someone could give a complete example: How to create a table with the 8D cube ? Sample Insert Lookup - exact matching Lookup - nearest neighbor matching Sample Data: For simplicity sake, we can assume that all the values range from 0-100. Point1: (1,1,1,1, 1,1,1,1) Point2: (2,2,2,2, 2,2,2,2)

pg_dump on Database throwing error 'out of shared memory'

别来无恙 提交于 2019-12-22 05:29:13
问题 Getting problem when taking backup on database contains around 50 schema with each schema having around 100 tables. pg_dump throwing below error suggesting that to increase max_locks_per_transaction . pg_dump: WARNING: out of shared memory pg_dump: SQL command failed pg_dump: Error message from server: ERROR: out of shared memory HINT: You might need to increase max_locks_per_transaction. pg_dump: The command was: SELECT tableoid, oid, prsname, prsnamespace, prsstart::oid, prstoken::oid,