RE: Localizing stored functions by replacing placeholders in their body

2021-03-02 Thread Kevin Brannen
-Original Message- From: Alvaro Herrera Sent: Tuesday, March 2, 2021 2:19 PM To: Alexander Farber Cc: pgsql-general Subject: Re: Localizing stored functions by replacing placeholders in their body On 2021-Mar-02, Alexander Farber wrote: > CREATE OR REPLACE FUNCTION localize_hello() >

self-made certs not quite right

2021-03-02 Thread Rob Sargent
I'm trying to follow instrux in V12:18.9.5 Creating Certificates. [1] I'm stuck in my basement so all references to "/CN=FQN" have been set to $(hostname), just the hostname, because $(domainname) returns "(none)" which I presume is akin to null. With my newly minted certs and keys using psql

Re: Locks in creating a partition in CREATE TABLE vs ALTER TABLE

2021-03-02 Thread Alvaro Herrera
On 2021-Mar-02, Asaf Flescher wrote: > I'm not sure if this is a bug or I'm missing something regarding how > partitioning is supposed to work but I've noticed (in Postgres 12.6) that > if I have a partitioned table, and then try to add a partition to it via > CREATE TABLE ... PARTITION OF, the st

Locks in creating a partition in CREATE TABLE vs ALTER TABLE

2021-03-02 Thread Asaf Flescher
Hi, I'm not sure if this is a bug or I'm missing something regarding how partitioning is supposed to work but I've noticed (in Postgres 12.6) that if I have a partitioned table, and then try to add a partition to it via CREATE TABLE ... PARTITION OF, the statement will grab an AccessExclusive lock

Aw: Re: Localizing stored functions by replacing placeholders in their body

2021-03-02 Thread Karsten Hilbert
> I'm not sure this is a great approach to in-database translations: you > have one function per string, which is cumbersome, bloated and probably > slow. I would suggest having a function that takes a string and returns > its translation, which is obtained from a couple of tables: one where > the

Re: Localizing stored functions by replacing placeholders in their body

2021-03-02 Thread Alvaro Herrera
On 2021-Mar-02, Alexander Farber wrote: > CREATE OR REPLACE FUNCTION localize_hello() > RETURNS text AS > $func$ > SELECT '$(hello)'; > $func$ LANGUAGE sql IMMUTABLE; I'm not sure this is a great approach to in-database translations: you have one function per string, which is cumb

Re: Localizing stored functions by replacing placeholders in their body

2021-03-02 Thread Alexander Farber
I think I will try this approach: \set localized_declaration `sed 's/this/that/' my_func.sql` :localized_declaration Thank you for your input

Re: Localizing stored functions by replacing placeholders in their body

2021-03-02 Thread Alexander Farber
Ah, I understand, that was the wrong EXECUTE, thank you. Another idea: can't I use \set command for my purpose of localizing stored functions? \set my_func_declaration `sed 's/this/that/' my_func.sql` But how to execute the declaration? I can only echo it with select (:'my_func_declaration');

Re: Localizing stored functions by replacing placeholders in their body

2021-03-02 Thread Pavel Stehule
út 2. 3. 2021 v 17:55 odesílatel Alexander Farber < alexander.far...@gmail.com> napsal: > Thank you for the \! hint, Pavel, didn't know about that! > > Is it possible to have a pure SQL solution? (To avoid having to install > "sed" on my Win 10 PC) > You should to use PLpgSQL EXECUTE statement, n

Re: Localizing stored functions by replacing placeholders in their body

2021-03-02 Thread Alexander Farber
Thank you for the \! hint, Pavel, didn't know about that! Is it possible to have a pure SQL solution? (To avoid having to install "sed" on my Win 10 PC) Maybe by using EXECUTE? EXECUTE REGEXP_REPLACE( $localize$ CREATE OR REPLACE FUNCTION my_func() RETURNS text AS $func$ SELECT

Re: Localizing stored functions by replacing placeholders in their body

2021-03-02 Thread Pavel Stehule
út 2. 3. 2021 v 17:18 odesílatel Alexander Farber < alexander.far...@gmail.com> napsal: > Or is it possible to call external commands from an sql script, like > > \i "sed 's/this/that/' some.sql" > you can use \! statement for execution of external statements Pavel

Re: Localizing stored functions by replacing placeholders in their body

2021-03-02 Thread Alexander Farber
Or is it possible to call external commands from an sql script, like \i "sed 's/this/that/' some.sql"

Re: Localizing stored functions by replacing placeholders in their body

2021-03-02 Thread Alexander Farber
Yes, good point about the '\$', thank you Tom. The reason I am trying not to use sed, is because I deploy my database by executing a single command: psql words_en < words_en.sql And the file words_en.sql has the contents: \i words_hash.sql \i words_all_letters.sql \i words_get_hint.sql \i words

Re: Localizing stored functions by replacing placeholders in their body

2021-03-02 Thread Tom Lane
Alexander Farber writes: > update pg_proc set prosrc = regexp_replace(prosrc, '$\(\w+\)','Hi > english','g') where proname='localize_hello'; "$" is a metacharacter in regexes ... writing \$ might help. (The idea of direct updates on the system catalogs seems like a really bad one. Why not pass

Localizing stored functions by replacing placeholders in their body

2021-03-02 Thread Alexander Farber
Hello, I have an app using PostgreSQL 13.2, in 6 different human languages (each using different database, but same source code). Currently to localize strings return/set by the stored functions I either get localized strings from a table or maintain stored function source code in 6 different lan

Re: Pgbackrest version 2.28 Bug/Issue

2021-03-02 Thread Reid Thompson
On Tue, 2021-03-02 at 14:16 +0530, Brajendra Pratap Singh wrote: >  unable to connect to 'dbname='postgres' port=5432': could not connect to > server: No such file or directory >                                         Is the server running locally and > accepting >                            

Re: Batch update million records in prd DB

2021-03-02 Thread Yi Sun
Hi Kristjan, Thank you for this information. "postgres the memory is slowly eaten away when doing updates within plsql loop" for this memory issue, I want to check if it exists in our current postgresql version. And let developer change to use python for loop also need to show them the proof, how

Re: Batch update million records in prd DB

2021-03-02 Thread Yi Sun
Hi Michael, Thank you, after create index to the temp table column, time cost become smaller Michael Lewis 于2021年3月2日周二 上午12:08写道: > 1) Don't pretend it is a left join when your where clause will turn it > into an INNER join. > LEFT JOIN pol gp ON gab.policy_id = gp.id > WHERE > > *

Re: Pgbackrest version 2.28 Bug/Issue

2021-03-02 Thread David Rowley
On Tue, 2 Mar 2021 at 21:53, Brajendra Pratap Singh wrote: > We are getting the below issue while executing the backup through pgbackrest. > 2021-03-02 02:10:01.622 P00 ERROR: [056]: unable to find primary cluster - > cannot proceed That's not an error that's coming from PostgreSQL. You might

Re: Batch update million records in prd DB

2021-03-02 Thread Kristjan Mustkivi
Hi Yi, I found that in postgres the memory is slowly eaten away when doing updates within plsql loop. It only gets released once the whole block completes. While it is ok for small tables you will eventually run out of memory for really big ones. The working approach was to do the loop in e.g a py

Pgbackrest version 2.28 Bug/Issue

2021-03-02 Thread Brajendra Pratap Singh
Hi , We are getting the below issue while executing the backup through pgbackrest. 2021-03-02 02:10:01.620 P00 INFO: backup command begin 2.28: --archive-check --archive-copy --compress --db-timeout=7200 --log-level-console=detail --log-level-file=detail --log-level-stderr=detail --log-path=/ap