postgresql-9.5

Postgres choosing BTREE instead of BRIN index

一曲冷凌霜 提交于 2019-12-23 07:36:34
问题 I'm running Postgres 9.5 and am playing around with BRIN indexes. I have a fact table with about 150 million rows and I'm trying to get PG to use a BRIN index. My query is: select sum(transaction_amt), sum (total_amt) from fact_transaction where transaction_date_key between 20170101 and 20170201 I created both a BTREE index and a BRIN index (default pages_per_range value of 128) on column transaction_date_key (the above query is referring to January to February 2017). I would have thought

Are the rows locked in order in a SELECT … ORDER BY … FOR UPDATE statement?

懵懂的女人 提交于 2019-12-21 12:52:33
问题 This question can be considered as a follow-up on my comment on Can two concurrent but identical DELETE statements cause a deadlock?. I am wondering if the rows are locked in ascending my_status order in the following statement: SELECT 1 FROM my_table ORDER BY my_status FOR UPDATE; There is an interesting remark on https://www.postgresql.org/docs/9.5/static/sql-select.html which says: It is possible for a SELECT command running at the READ COMMITTED transaction isolation level and using ORDER

Are the rows locked in order in a SELECT … ORDER BY … FOR UPDATE statement?

Deadly 提交于 2019-12-21 12:52:08
问题 This question can be considered as a follow-up on my comment on Can two concurrent but identical DELETE statements cause a deadlock?. I am wondering if the rows are locked in ascending my_status order in the following statement: SELECT 1 FROM my_table ORDER BY my_status FOR UPDATE; There is an interesting remark on https://www.postgresql.org/docs/9.5/static/sql-select.html which says: It is possible for a SELECT command running at the READ COMMITTED transaction isolation level and using ORDER

Are the rows locked in order in a SELECT … ORDER BY … FOR UPDATE statement?

╄→гoц情女王★ 提交于 2019-12-21 12:52:08
问题 This question can be considered as a follow-up on my comment on Can two concurrent but identical DELETE statements cause a deadlock?. I am wondering if the rows are locked in ascending my_status order in the following statement: SELECT 1 FROM my_table ORDER BY my_status FOR UPDATE; There is an interesting remark on https://www.postgresql.org/docs/9.5/static/sql-select.html which says: It is possible for a SELECT command running at the READ COMMITTED transaction isolation level and using ORDER

PostgreSQL INSERT ON CONFLICT UPDATE (upsert) use all excluded values

笑着哭i 提交于 2019-12-18 10:12:14
问题 When you are upserting a row (PostgreSQL >= 9.5), and you want the possible INSERT to be exactly the same as the possible UPDATE, you can write it like this: INSERT INTO tablename (id, username, password, level, email) VALUES (1, 'John', 'qwerty', 5, 'john@mail.com') ON CONFLICT (id) DO UPDATE SET id=EXCLUDED.id, username=EXCLUDED.username, password=EXCLUDED.password, level=EXCLUDED.level,email=EXCLUDED.email Is there a shorter way? To just say: use all the EXCLUDE values. In SQLite I used to

Postgresql - unable to drop database because of some auto connections to DB

吃可爱长大的小学妹 提交于 2019-12-18 09:54:20
问题 Whenever I try to drop database I get: ERROR: database "pilot" is being accessed by other users DETAIL: There is 1 other session using the database. When I use: SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'TARGET_DB'; I terminated the connection from that DB, but if I try to drop database after that somehow someone automatically connects to that database and gives this error. What could be doing that? No one uses this database,

Updatable VIEW doesn't work with ON CONFLICT in Postgres 9.5

旧城冷巷雨未停 提交于 2019-12-12 20:03:10
问题 PostgreSQL version: 9.5.4 I have a table defined as: CREATE TABLE IF NOT EXISTS TEST_1 ( ID SERIAL PRIMARY KEY, C1 BYTEA, C2 TEXT NOT NULL, C3 BOOLEAN NOT NULL DEFAULT FALSE, CONSTRAINT TEST_1_unique_idx UNIQUE(C1, C2) ); I have a view defined as: create or replace view test as select * from test_1 with cascaded check option; This is necessary to abstract from table name while application code is working via view name (to implement a kind of simple partitioning with replacing tables when

Postgresql query to get count per months within one year

自作多情 提交于 2019-12-12 19:21:56
问题 In MySQL SELECT y, m, Count(users.created_date) FROM ( SELECT y, m FROM (SELECT YEAR(CURDATE()) y UNION ALL SELECT YEAR(CURDATE())-1) years, (SELECT 1 m UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12) months) ym LEFT JOIN users ON ym.y = YEAR(FROM_UNIXTIME(users.created_date)) AND ym.m = MONTH(FROM_UNIXTIME(users.created_date))

How to install Postgis to a Keg installation of Postgres@9.5 using Homebrew?

流过昼夜 提交于 2019-12-12 18:19:17
问题 I have installed Postgresql@9.5 to my OSX El Capitan Machine using Homebrew 1.2. Unfortunately, upon installing Postgis, and performing CREATE EXTENSION postgis; It returns, ERROR: could not open extension control file "/usr/local/Cellar/postgresql@9.5/9.5.6/share/postgresql@9.5/extension/postgis.control": No such file or directory I tried, uninstalling all postgresql and install only the 9.5 version, and then installing postgis but to no avail. I think I got a similar question but this one

Install plpython3u for PostgreSQL 9.5 on CentOS 7.2

安稳与你 提交于 2019-12-12 15:06:52
问题 Try as I might, I have not succeeded in installing the plpython3u extension on a PostgreSQL 9.5 x64 install. PostgreSQL 9.5 installed from pgdg repo: [joe@postgresql ~]$ yum list installed | grep pgdg CGAL.x86_64 4.7-1.rhel7 @pgdg95 SFCGAL.x86_64 1.2.2-1.rhel7 @pgdg95 SFCGAL-libs.x86_64 1.2.2-1.rhel7 @pgdg95 geos.x86_64 3.5.0-1.rhel7 @pgdg95 pgdg-centos95.noarch 9.5-2 installed plv8_95.x86_64 1.4.4-1.rhel7 @pgdg95 postgis2_95.x86_64 2.2.2-1.rhel7 @pgdg95 postgis2_95-client.x86_64 2.2.2-1