postgresql

How to optimize query if I already use GIN index

徘徊边缘 提交于 2021-01-29 22:19:41
问题 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.

Updating a table to create unique ids in from a substring in PostgreSQL

a 夏天 提交于 2021-01-29 22:07:37
问题 I have table1 with following columns and example of data: id, condition1, condition2, condition3, target_id 1, Westminster, Abbey Road, NW1 1FS, null 2, Westminster, Abbey Road, NW1 1FG, null 3, Westminster, China Road, NW1 1FG, null 4, Wandsworth, China Road, SE5 3LG, null 5, Wandsworth, China Road, SE5 3LS, null Intended result for the target_id would be: id, condition1, condition2, condition3, target_id 1, Westminster, Abbey Road, NW1 1FS, 1 2, Westminster, Abbey Road, NW1 1FG, 1 3,

Cannot configure pgpool with master and slave nodes

╄→гoц情女王★ 提交于 2021-01-29 22:02:12
问题 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

PostgreSQL: How to select and update from a table as if it were a queue

假如想象 提交于 2021-01-29 20:51:37
问题 I'd like several processes to pull from a table as if it were a queue. The requirements: Order of the items is important, and must be specified in the query Each process (of which there are an unknown amount) can get chunks of N items at a time Each item must only be processed once I don't want to lock the table (for performance reasons) I have a working solution, but would like some other opinions. First attempt: UPDATE foo SET should_select=0 FROM (SELECT * FROM foo WHERE should_select=1

Updating a table to create unique ids in from a substring in PostgreSQL

对着背影说爱祢 提交于 2021-01-29 20:50:42
问题 I have table1 with following columns and example of data: id, condition1, condition2, condition3, target_id 1, Westminster, Abbey Road, NW1 1FS, null 2, Westminster, Abbey Road, NW1 1FG, null 3, Westminster, China Road, NW1 1FG, null 4, Wandsworth, China Road, SE5 3LG, null 5, Wandsworth, China Road, SE5 3LS, null Intended result for the target_id would be: id, condition1, condition2, condition3, target_id 1, Westminster, Abbey Road, NW1 1FS, 1 2, Westminster, Abbey Road, NW1 1FG, 1 3,

postgres create rule on insert do nothing if exists insert otherwise; RETURNING id

两盒软妹~` 提交于 2021-01-29 20:30:07
问题 In Postgres, is it possible to CREATE RULE which does nothing if some key exists but inserts otherwise. In either case it should return the id of the inserted/skipped row. I need a rule, so please do not give alternates. I currently have the below rule that does nothing on conflicting inserts and I want to perform an insert with RETURNING id clause but I am getting the below error ERROR: cannot perform INSERT RETURNING on relation "fco_assets" HINT: You need an unconditional ON INSERT DO

Arithmetic Division For Two Table In SQL (PostgreSQL)

假如想象 提交于 2021-01-29 20:19:35
问题 I am trying to do a very simple division in SQL (PostgreSQL). I want to get the count of all the record from two tables, and divide them and output to another table. For example, we have two tables, table1 and table2 SELECT COUNT(*) FROM table1; SELECT COUNT(*) FROM table2; Now the above queries will be both one column one row, which is the count of the table1 and table2. I would like to get the two number divide ( COUNT(TABLE1)/COUNT(TABLE2) ), how should I do this in SQL? 回答1: Well, you can

Combine multiple rows with different dates with overlapping variables (to capture first and last change dates)

馋奶兔 提交于 2021-01-29 20:18:05
问题 I have the following data represented in a table like this: User Type Date A Mobile 2019-01-10 A Mobile 2019-01-20 A Desktop 2019-03-01 A Desktop 2019-03-20 A Email 2021-01-01 A Email 2020-01-02 A Desktop 2021-01-03 A Desktop 2021-01-04 A Desktop 2021-01-05 Using PostgreSQL - I want to achieve the following: User First_Type First Type Initial Date Last_Type Last_Type_Initial_Date A Mobile 2019-01-10 Desktop 2021-01-03 So for each user, I want to capture the initial date and type but then also

Migrating data between different schemas

有些话、适合烂在心里 提交于 2021-01-29 20:17:32
问题 I have a small django website where people have signed up and uploaded pictures and stuff. I now want to rebuild the website API. This will change the database schema and I want to migrate all the user information from old database to new database. Whats the best practice of doing this? Links to tutorials will be helpful. The database backend is postgres-postgis. TIA 回答1: There are different approaches to data migration. In my previous employer we rewrote much of the code from scratch and

SQL Query to count between range of minimum date and date in other column

旧城冷巷雨未停 提交于 2021-01-29 19:50:45
问题 temp |id|received |changed | |33|2019-02-18|2019-11-18| |33|2019-08-02|2019-11-18| |33|2019-12-27|2019-11-18| |18|2019-07-14|2019-10-18| |50|2019-03-20|2019-05-26| |50|2019-01-19|2019-05-26| The 'temp' table shows users who received a request for an activity. A user can make multiple requests. Hence the received column has multiple dates showing when the requests was received. The 'changed' table shows when the status was changed. Hence there will be only 1 value per user for 'changed'. Need