postgresql

PostgreSQL uninstall on Windows

[亡魂溺海] 提交于 2021-01-29 18:03:21
问题 In the process of upgrading from PostgreSQL 11 to 12 on Windows, I uninstall PG-11 using the uninstall.exe, wait for like 15 seconds (to make sure that the uninstall.exe is complete), delete the bindir (if exists) and then install the Postgres-12.exe. This all is done in a batch file and the code looks something like: uninstall-postgresql.exe --mode unattended PING 1.1.1.1 -n 15 >NUL if exist C:\PostgreSQL\bindir RD /Q /S C:\PostgreSQL\bindir postgresql-12.1.exe --servicename Postgres -

Cannot configure pgpool with master and slave nodes

房东的猫 提交于 2021-01-29 17:24:54
问题 I have created a master-slave postgreSQL (I have one cluster as main and the other one as hot_standby). All local host. I used the "pgpool.conf.sample" and changed the backend 1+2 for my master and slave nodes. whenever I open the pgpool and run show pool_nodes; I can see the master + slave but slave is on waiting status. If I return to the configuration file and turn on the master_slave_mode, now both nodes are "up" but they're standby and all goes through the master one. What i'm trying to

JOIN table if condition is satisfied, else perform no join

ⅰ亾dé卋堺 提交于 2021-01-29 16:54:23
问题 I have one table transaction and another table transaction_item . One transaction has multiple transaction_items. I want to left join transaction_item if transaction_item.amount >= 2 , else perform no join. select ti.* from transaction t LEFT JOIN transaction_item ti on ti.unique_id = t.unique_id AND ti.location_id = t.location_id AND ti.transaction_date = t.transaction_date AND ti.amount >= 2 where t.pos_transaction_id = 4220 and t.location_id = 1674 and t.transaction_date = '2020-05-08'; If

How to optimize query if I already use GIN index

半腔热情 提交于 2021-01-29 16:42:34
问题 I use (PostgreSQL) 11.8 and I try to provide full text search opportunity by some columns. For that I created GIN index with multiple fields and coalesce. And after my data base grewto 344747 rows in table products I faced with slow execution in my query. When I execute query example I faced with approximately 4.6s. In analyzing information I see my index used, but still slowly. Bitmap Index Scan on npdbcs_swedish_custom_index present. If I correct made conclusion many time spent to grouping.

Close an existing Postgres connection using psycopg2

别说谁变了你拦得住时间么 提交于 2021-01-29 16:25:15
问题 I was playing around with Postgresql and psycopg2 . I think I started many connections using the terminal but never closed it. Using pyscopg2 I understood how to start a connection and close it too. Now I was trying to get the existing connection (that i launched using the terminal before) using pyscopg2 but it seems there is an issue with port number. When I run SELECT * FROM pg_stat_activity ; , these are my results datid | datname | pid | usesysid | usename | application_name | client_addr

FATAL: bogus data in lock file “postmaster.pid” after repairing disk and changing the data folder location postgres docker

牧云@^-^@ 提交于 2021-01-29 16:18:53
问题 We had a problem with our hard drive which contains the data folder for postgres database we repaired that hard and move the data folder to new hard drive now when we try to start our db container we get following error. db_1 | db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization db_1 | db_1 | FATAL: bogus data in lock file "postmaster.pid": "" I tried to remove the postmaster.pid file but then I get the following error, db_1 | PostgreSQL Database

no pg_hba.conf entry for host / Connect call failed / Invalid data directory for cluster 12 main - Postgresql Ubuntu

丶灬走出姿态 提交于 2021-01-29 15:40:28
问题 I'm trying to move my bot to an Ubuntu virtual server from Vultr but it's having a problem connecting to the postgres database. I've tried editing the config from md5 to true, and host to local, etc. But those only give me different errors and also make it stop working on my original machine too. It's working perfectly fine on my Windows machine. Here is the error I'm facing: asyncpg.exceptions.InvalidAuthorizationSpecificationError: no pg_hba.conf entry for host "[local]", user "postgres",

Postgresql - Merge rows into jsonb object

别说谁变了你拦得住时间么 提交于 2021-01-29 15:34:43
问题 (This is a follow up question after Postgresql - Count freuency of array or jsonb object) In postgresql 12+, given following input rows: The expected output is: uid tag_freq 1 {'a':2, 'b':1, 'c':1} 2 {'a':1, 'b':2, 'c':2, 'e':1} ... Output column tag_freq is jsonb object, and it's merged result for a user. Is there any way to write such a query? 回答1: You can use jsonb_object_agg() for this: select uid, jsonb_object_agg(tag, count) as tag_freq from the_table group by uid; 来源: https:/

Aggregating distinct values from JSONB arrays combined with SQL group by

余生颓废 提交于 2021-01-29 15:13:11
问题 I am trying to aggregate distinct values from JSONB arrays in a SQL GROUP BY statement: One dataset has many cfiles and a cfile only ever has one dataset SELECT * FROM cfiles; id | dataset_id | property_values (jsonb) ----+------------+----------------------------------------------- 1 | 1 | {"Sample Names": ["SampA", "SampB", "SampC"]} 2 | 1 | {"Sample Names": ["SampA", "SampB", "SampD"]} 3 | 1 | {"Sample Names": ["SampE"]} 4 | 2 | {"Sample Names": ["SampA", "SampF"]} 5 | 2 | {"Sample Names":

Insert into table with a foreign key

不羁的心 提交于 2021-01-29 14:52:31
问题 Using Postgresql Customer Nmb_id | Order History | Search | Contacts Primary_Key | Nmb_id_fk | Fax | Email | Nmb_id_fk is a foreign key to the Customer primary key Nmb_id. Trying to insert data into a table with a FK relationship: SQL: insert into contacts (fax, email, Nmb_id_fk) values( '123', 'a@a.com', (select "Nmb_id" from customer where "Nmd_id" = 4)); Keep getting error: ERROR: column "Nmb_id_fk" of relation "contacts" does not exist 回答1: insert into contacts (fax, email, "Nmb_id_fk")