Re: PostgreSQL 9.2 high replication lag

2021-08-19 Thread Laurenz Albe
On Fri, 2021-08-20 at 01:33 +, Lucas wrote: > After setting max_standby_streaming_delay to 120s it got a lot better. > But the replication delay is still happening quite often, except this time > goes up to 120s only. That's exactly what this parameter should do. If you don't want the delay

Re: PostgreSQL 9.2 high replication lag

2021-08-19 Thread Lucas
Hello guys. After setting max_standby_streaming_delay to 120s it got a lot better. But the replication delay is still happening quite often, except this time goes up to 120s only. [image.png] I know that max_standby_streaming_delay stands for how long the standby server should wait before canc

Re: string_agg distinct order by

2021-08-19 Thread Michael Lewis
I believe that you could define an enumerated type to use for those status colors such that the ordering is defined as you like without two separate columns for the name and sort_value or whatever. https://www.postgresql.org/docs/current/datatype-enum.html Example in the documentation expanded a

Re: Regexp_replace bug / does not terminate on long strings

2021-08-19 Thread Michael Lewis
Btw- My apologies for top posting. I think my caffeine wore off.

Re: Regexp_replace bug / does not terminate on long strings

2021-08-19 Thread Michael Lewis
If you need it ordered, this is a bit awkward but works and returns for me in about 5ms on my dev machine. select string_agg( value, ',' ) As final_result from( select value, min( row_num ) as min_row_num from( select sub.value, row_number() over () as row_num from ( select unnest( strin

Re: Regexp_replace bug / does not terminate on long strings

2021-08-19 Thread Tom Lane
"Markhof, Ingolf" writes: > BRIEF: > regexp_replace(source,pattern,replacement,flags) needs very (!) long to > complete or does not complete at all (?!) for big input strings (a few k > characters). (Oracle SQL completes the same in a few ms) Regexps containing backrefs are inherently hard --- ev

Re: Selecting table row with latest date [RESOLVED]

2021-08-19 Thread Adrian Klaver
On 8/19/21 3:07 PM, Rich Shepard wrote: On Thu, 19 Aug 2021, David G. Johnston wrote: David, I'm not at all surprised as I use postgres infrenquently. Once I have queries producing results I need for my business tracking or client data I just use them. I'm neither a professional DBA nor data

Re: Selecting table row with latest date [RESOLVED]

2021-08-19 Thread Rich Shepard
On Thu, 19 Aug 2021, David G. Johnston wrote: Well, in this case I suspect you had made a different mistake which caused the error message (probably the max(c.next_contact)) but instead of solving the original problem (removing the max(...)) you decided that two wrongs (adding or extending a gro

Re: Selecting table row with latest date [RESOLVED]

2021-08-19 Thread David G. Johnston
On Thu, Aug 19, 2021 at 2:52 PM Rich Shepard wrote: > On Thu, 19 Aug 2021, David G. Johnston wrote: > > > I thought you said (p.person_nbr, c.contact_date) is already unique? > > Yes, that's the PK for the contacts table. I'm still unsure what needs to > be > explicitly included in a query. Quite

Re: Selecting table row with latest date [RESOLVED]

2021-08-19 Thread Rich Shepard
On Thu, 19 Aug 2021, David G. Johnston wrote: I thought you said (p.person_nbr, c.contact_date) is already unique? David, Yes, that's the PK for the contacts table. I'm still unsure what needs to be explicitly included in a query. Quite often I leave out a column and postgres tells me it need

Re: Selecting table row with latest date [RESOLVED]

2021-08-19 Thread David G. Johnston
On Thu, Aug 19, 2021 at 12:34 PM Rich Shepard wrote: > group by p.person_nbr, c.contact_date > I thought you said (p.person_nbr, c.contact_date) is already unique? David J.

Re: Selecting table row with latest date [RESOLVED]

2021-08-19 Thread Rich Shepard
On Thu, 19 Aug 2021, David G. Johnston wrote: Yeah, you wrote two from clauses… David, Mea culpa! I did. Got that fixed. Now, this query: --- Select distinct on (p.person_nbr) p.person_nbr, c.contact_date, max(c.next_contact) as next_contac from contacts, people as p, contacts as c where

Re: Selecting table row with latest date

2021-08-19 Thread Adrian Klaver
On 8/19/21 10:17 AM, Rich Shepard wrote: On Thu, 19 Aug 2021, Adrian Klaver wrote: So take David Johnston's query: Select distinct on (person_nbr) ….. order by person_nbr, contact_date desc; Adrian, contact_date --  2021-08-17  2019-05-14  2019-05-15  2021-08-17  2018-04-05

Re: Licensing

2021-08-19 Thread Bruce Momjian
On Thu, Aug 19, 2021 at 04:07:52PM +0200, Magnus Hagander wrote: > On Thu, Aug 19, 2021 at 2:34 AM Bruce Momjian wrote: > > > > On Wed, Aug 18, 2021 at 12:47:26PM -0700, Bryan Boone wrote: > > > Ah okay thank you. I think what was confusing me was the “without fee”. > > > > > > I wasn’t sure if t

Re: Selecting table row with latest date

2021-08-19 Thread David G. Johnston
On Thursday, August 19, 2021, Rich Shepard wrote: > On Thu, 19 Aug 2021, Adrian Klaver wrote: > > So take David Johnston's query: >> Select distinct on (person_nbr) ….. order by person_nbr, contact_date >> desc; >> > > Adrian, > > contact_date -- > 2021-08-17 What’s your point?

Re: Selecting table row with latest date

2021-08-19 Thread Rob Sargent
> On Aug 19, 2021, at 11:20 AM, Rich Shepard wrote: > > On Thu, 19 Aug 2021, Rob Sargent wrote: > >> sorry, wasn’t clear: person_nbr, next_contact >> On the premise that there can only be one next date. > > Rob, > > I wasn't sufficiently clear. The contacts table has a row for each > (perso

Re: Selecting table row with latest date

2021-08-19 Thread Rich Shepard
On Thu, 19 Aug 2021, Rob Sargent wrote: sorry, wasn’t clear: person_nbr, next_contact On the premise that there can only be one next date. Rob, I wasn't sufficiently clear. The contacts table has a row for each (person_nbr, contact_date). For each row there's also either a next_contact date o

Re: Selecting table row with latest date

2021-08-19 Thread Rich Shepard
On Thu, 19 Aug 2021, Adrian Klaver wrote: So take David Johnston's query: Select distinct on (person_nbr) ….. order by person_nbr, contact_date desc; Adrian, contact_date -- 2021-08-17 2019-05-14 2019-05-15 2021-08-17 2018-04-05 2021-08-17 2018-04-05 2021-07-23 2019-04-

Re: Selecting table row with latest date

2021-08-19 Thread Rob Sargent
> On Aug 19, 2021, at 10:59 AM, Rich Shepard wrote: > > On Thu, 19 Aug 2021, Rob Sargent wrote: > >> Yeah, but my quibble is the the table you described up-thread. Your >> contact table contains next_contact? I think that column should be >> normalized out. > > Rob, > > Why should I have a

Re: Selecting table row with latest date

2021-08-19 Thread Rich Shepard
On Thu, 19 Aug 2021, Rob Sargent wrote: Yeah, but my quibble is the the table you described up-thread. Your contact table contains next_contact? I think that column should be normalized out. Rob, Why should I have a separate table with one column: next_contact? The next_contact date is associ

Re: Selecting table row with latest date

2021-08-19 Thread Adrian Klaver
On 8/19/21 9:06 AM, Rich Shepard wrote: On Thu, 19 Aug 2021, Adrian Klaver wrote: Alright now I am confused. You keep referring to contact_date, yet the query is referring to next_contact. Are they the same thing, different things or other? Adrian, The table has 5 columns: person_nbr, contac

Re: Selecting table row with latest date

2021-08-19 Thread Rob Sargent
> On Aug 19, 2021, at 10:31 AM, Rich Shepard wrote: > > On Thu, 19 Aug 2021, Rob Sargent wrote: > >> Did you try David J’s suggestion? or maybe > > Rob, > > Yes. > >> select person_nbr, max(next_contact) group by person_nbr where >> next_contact < now(); > >> A table with person_nbr (pk),

Re: Selecting table row with latest date

2021-08-19 Thread Rich Shepard
On Thu, 19 Aug 2021, Rob Sargent wrote: Did you try David J’s suggestion? or maybe Rob, Yes. select person_nbr, max(next_contact) group by person_nbr where next_contact < now(); A table with person_nbr (pk), next_contact would make this much easier. Seems to me a person can only have one

Re: string_agg distinct order by

2021-08-19 Thread Tom Lane
"Markhof, Ingolf" writes: > I am looking for something like > string_agg(distinct col_x order by col_y) > Unfortunately, you can either have the distinct, but then the order by > needs to be identical to what's aggregated, or you can have the order be > determined by another column. Not both...

Re: string_agg distinct order by

2021-08-19 Thread David G. Johnston
On Thu, Aug 19, 2021 at 9:09 AM Markhof, Ingolf < ingolf.mark...@de.verizon.com> wrote: > > > string_agg(distinct status,',' order by status) as list > > but this is not what I want: 'green' would get first, red second, yellow last... > > I could also drop the distinct and say: > > string_agg(statu

Re: Selecting table row with latest date

2021-08-19 Thread Rob Sargent
> On Aug 19, 2021, at 10:06 AM, Rich Shepard wrote: > > On Thu, 19 Aug 2021, Adrian Klaver wrote: > >> Alright now I am confused. You keep referring to contact_date, yet the >> query is referring to next_contact. Are they the same thing, different >> things or other? > > Adrian, > > The tabl

Re: PostgreSQL Automatic Failover Windows Server

2021-08-19 Thread Laurenz Albe
On Wed, 2021-08-18 at 21:18 +0530, Heljeeve C Unni wrote: > I want to know in detail about PostgreSQL Automatic Failover solutions > without third party tools. > > Installation procedures step by step on WINDOWS SERVER. You could have a look at this: https://github.com/cybertec-postgresql/patro

string_agg distinct order by

2021-08-19 Thread Markhof, Ingolf
I am looking for something like string_agg(distinct col_x order by col_y) Unfortunately, you can either have the distinct, but then the order by needs to be identical to what's aggregated, or you can have the order be determined by another column. Not both... Here is the playground Given: crea

Re: Selecting table row with latest date

2021-08-19 Thread Rich Shepard
On Thu, 19 Aug 2021, Adrian Klaver wrote: Alright now I am confused. You keep referring to contact_date, yet the query is referring to next_contact. Are they the same thing, different things or other? Adrian, The table has 5 columns: person_nbr, contact_date, contact_type, notes, and next_con

Re: Selecting table row with latest date

2021-08-19 Thread Adrian Klaver
On 8/19/21 8:39 AM, Rich Shepard wrote: On Thu, 19 Aug 2021, Tom Lane wrote: The best way is usually like    select * from mytable order by contact_date desc limit 1; If you have an index on contact_date this should work very well indeed. tom, I added an index on contact_date and the query r

Re: Selecting table row with latest date

2021-08-19 Thread Rich Shepard
On Thu, 19 Aug 2021, Tom Lane wrote: The best way is usually like select * from mytable order by contact_date desc limit 1; If you have an index on contact_date this should work very well indeed. tom, I added an index on contact_date and the query returned only one row. Huh! Not what I exp

Selecting table row with latest date

2021-08-19 Thread David G. Johnston
On Thursday, August 19, 2021, Rich Shepard wrote: > On Thu, 19 Aug 2021, Rich Shepard wrote: > > Please point me to the proper place in the docs where I can learn how to do >> this. >> > > If I use DISTINCT ON would this produce the most recent date for each > person_nbr? > Yes, I mis-read your

Re: Selecting table row with latest date

2021-08-19 Thread Rich Shepard
On Thu, 19 Aug 2021, Tom Lane wrote: The best way is usually like select * from mytable order by contact_date desc limit 1; If you have an index on contact_date this should work very well indeed. Tom, I don't have an index on that table. I'll add one and try you suggestion. Thanks, Ric

Re: Selecting table row with latest date

2021-08-19 Thread Rich Shepard
On Thu, 19 Aug 2021, David G. Johnston wrote: Select distinct on (person_nbr) ….. order by person_nbr, contact_date desc; David, Please clarify: would this produce the most recent contact_date for each person_nbr? The manual reads that two rows (e.g., for the same person_nbr) are considered d

Re: Selecting table row with latest date

2021-08-19 Thread Adrian Klaver
On 8/19/21 7:37 AM, Rich Shepard wrote: I have a table of contacts (PK is the person_nbr and contact_date) and I want to select only the row with the latest (most recent) contact_date. The Comparison Date/Time sections in the postgres 12 doc doesn't appear to have what I want, and when I try to u

Re: Selecting table row with latest date

2021-08-19 Thread Tom Lane
Rich Shepard writes: > I have a table of contacts (PK is the person_nbr and contact_date) and I > want to select only the row with the latest (most recent) contact_date. The > Comparison Date/Time sections in the postgres 12 doc doesn't appear to have > what I want, and when I try to use the max()

Re: Selecting table row with latest date

2021-08-19 Thread Rich Shepard
On Thu, 19 Aug 2021, Rich Shepard wrote: Please point me to the proper place in the docs where I can learn how to do this. If I use DISTINCT ON would this produce the most recent date for each person_nbr? Rich

Re: Selecting table row with latest date

2021-08-19 Thread David G. Johnston
On Thursday, August 19, 2021, Rich Shepard wrote: > I have a table of contacts (PK is the person_nbr and contact_date) > Select distinct on (person_nbr) ….. order by person_nbr, contact_date desc; David J.

Selecting table row with latest date

2021-08-19 Thread Rich Shepard
I have a table of contacts (PK is the person_nbr and contact_date) and I want to select only the row with the latest (most recent) contact_date. The Comparison Date/Time sections in the postgres 12 doc doesn't appear to have what I want, and when I try to use the max() aggregate function it throws

Re: How to detach a database

2021-08-19 Thread Tom Lane
"David G. Johnston" writes: > On Thursday, August 19, 2021, sivapostg...@yahoo.com > wrote: >> Is there any way to make a PG database either in-active or switch to >> single-user mode ? We want to avoid DELETE database process. > Probably can do it via changing the pg_hba.conf file. Either tha

Re: How to detach a database

2021-08-19 Thread David G. Johnston
On Thursday, August 19, 2021, sivapostg...@yahoo.com wrote: > > Is there any way to make a PG database either in-active or switch to > single-user mode ? We want to avoid DELETE database process. > Probably can do it via changing the pg_hba.conf file. David J.

Re: How to detach a database

2021-08-19 Thread sivapostg...@yahoo.com
Hello, We want to carry out some data manipulation work in a database exclusively.    We don't want any one to connect this database during that time.   How to do it ? In SQL Server there are two ways [ earlier we used SQL Server and now switched to PG ]1.  Change the database to work in single-u

Re: Licensing

2021-08-19 Thread Magnus Hagander
On Thu, Aug 19, 2021 at 2:34 AM Bruce Momjian wrote: > > On Wed, Aug 18, 2021 at 12:47:26PM -0700, Bryan Boone wrote: > > Ah okay thank you. I think what was confusing me was the “without fee”. > > > > I wasn’t sure if that meant we could distribute it, but only if we did not > > charge a fee fo

Regexp_replace bug / does not terminate on long strings

2021-08-19 Thread Markhof, Ingolf
BRIEF: regexp_replace(source,pattern,replacement,flags) needs very (!) long to complete or does not complete at all (?!) for big input strings (a few k characters). (Oracle SQL completes the same in a few ms) VERBOSE Given a comma-separated list of "words" (whereas a word is any sequence of char