Do stuck replication slots prevent autovacuum of running entirely?

2025-05-20 Thread Marcelo Fernandes
Hi there, I am trying to understand if a stuck replication slot would be sufficient to stop an autovacuum of even starting. Couldn't the autovacuum process start, but fail to remove dead tuples that are still necessary by the replication slot? Why would it prevent autovacuum of even starting inst

Resetting the lock_timeout value for a transaction

2025-04-27 Thread Marcelo Fernandes
Hi folks, I have been using: -- Setting the SESSION lock timeout to 10 seconds SET lock_timeout = '10s'; -- Setting the TRANSACTION lock timeout to 20 seconds BEGIN; SET LOCAL lock_timeout = '20s'; COMMIT; However, I have been caught by the behaviour of "RESET lock_timeout;" when in

Changing default fillfactor for the whole database

2025-04-26 Thread Marcelo Fernandes
Hi there, I have a scenario where virtually all user tables in the database will need to have a lower fill factor. It would have been handy to have a way to set this default, but as of now, I don't think the default can be changed. I have looked at `share/postgresql.conf.sample` file, and couldn

pg_get_serial_sequence not working for manually set seq

2025-04-21 Thread Marcelo Fernandes
Hi folks, I've been testing the pg_get_serial_sequence function and noticed that I can only get reliable results when using a SERIAL or IDENTITY column. However, shouldn't it work for manually set sequences too? In the docs[0] we have that this function: > Returns the name of the sequence assoc

Best way to check if a table is empty

2025-04-05 Thread Marcelo Fernandes
Hi folks, I came up with three strategies to verify whether a table is empty. I wanted to sound the community to check whether my assumptions are correct for each of these strategies, and to also discuss which strategy is best. ## Strategy 1 [possibly best?] SELECT EXISTS (SELECT 1 FROM foo LIM

Default Value Retention After Dropping Default

2025-02-23 Thread Marcelo Fernandes
Hi folks, I am experiencing an interesting behavior in PostgreSQL and would like to seek some clarification. In the following snippet, I first add a column with a default value, then drop that default. However, when I query the table, the column still retains the dropped default for existing rows

Re: Best Approach for Swapping a Table with its Copy

2025-02-16 Thread Marcelo Fernandes
On Sat, Feb 15, 2025 at 4:12 AM Greg Sabino Mullane wrote: > The pg_repack link posted earlier has the details on how it is done. But > messing with system catalogs like this is highly discouraged, for good > reasons. Still, if you need to go that route, test heavily and post the > solutions he

Re: Best Approach for Swapping a Table with its Copy

2025-02-13 Thread Marcelo Fernandes
On Fri, Feb 14, 2025 at 12:35 PM Adrian Klaver wrote: > 1) In a previous post you said: > > "Yes, in this scenario the copy is already created, and triggers keep > the copy in sync with the original table." > > In that case the copy will already have TOAST tables associated with it. If we follow

Re: Best Approach for Swapping a Table with its Copy

2025-02-13 Thread Marcelo Fernandes
what I am trying to solve. If you have pointers, thoughts, or resources where I can better understand what's involved, that would be much appreciated. In terms of where I am at currently, I summarised in my previous reply: On Fri, Feb 14, 2025 at 11:59 AM Marcelo Fernandes wrote: > The p

Re: Best Approach for Swapping a Table with its Copy

2025-02-13 Thread Marcelo Fernandes
On Thu, Feb 13, 2025 at 7:37 PM Laurenz Albe wrote: > Yes, but only if you are willing to write C code that runs inside the > database server. That way, you can do anything (and cause arbitrary > damage). > > The big challenge here would be to do the swap in a safe way. How do > you intend to gu

Re: Best Approach for Swapping a Table with its Copy

2025-02-12 Thread Marcelo Fernandes
On Thu, Feb 13, 2025 at 1:33 PM Adrian Klaver wrote: > Not seeing it: > > https://reorg.github.io/pg_repack/ > > "Details > Full Table Repacks > > [...] > > pg_repack will only hold an ACCESS EXCLUSIVE lock for a short period > during initial setup (steps 1 and 2 above) and during the final > swap

Re: Best Approach for Swapping a Table with its Copy

2025-02-12 Thread Marcelo Fernandes
On Thu, Feb 13, 2025 at 10:40 AM Adrian Klaver wrote: > Do you know this will not fail on the existing data? Yes, all the current data in the original table respects the constraint. > Do you have room for a complete copy of the table? Yes, in this scenario the copy is already created, and trigg

Re: Best Approach for Swapping a Table with its Copy

2025-02-12 Thread Marcelo Fernandes
On Thu, Feb 13, 2025 at 10:02 AM Adrian Klaver wrote: > This needs more information: > 1) Postgres version. That would be for Postgres 15. > 2) The table definition. This is a simplified version of the original table: CREATE TABLE bookings ( id SERIAL PRIMARY KEY, resource_id INT NOT N

Best Approach for Swapping a Table with its Copy

2025-02-12 Thread Marcelo Fernandes
Hi folks, I have a scenario where I need to swap an original table with a copy of that table. The copy has an exclusion constraint that the original does not have. The main challenge is to ensure that the swap does not break any existing foreign keys to the original table and handles the associat

Re: Logging queries executed by SPI_execute

2025-02-03 Thread Marcelo Fernandes
On Mon, Feb 3, 2025 at 6:46 PM Pavel Stehule wrote: > The queries executed by SPI are never executed on the top level. These > queries are marked as nested. > > So you need to use auto_explain > https://www.postgresql.org/docs/current/auto-explain.html with active > auto_explain.log_nested_stat

Re: What is the story behind _SPI_PLAN_MAGIC?

2025-02-02 Thread Marcelo Fernandes
On Mon, Feb 3, 2025 at 3:17 PM Tom Lane wrote: > Just to catch programming errors, ie passing the wrong pointer > value to some SPI function. See the checks for it in spi.c. Aha! Perfect, I thought it was something like that. Thank you! Marcelo.

What is the story behind _SPI_PLAN_MAGIC?

2025-02-02 Thread Marcelo Fernandes
Hi there, Reading through the SPI code I see this definition: #define _SPI_PLAN_MAGIC 569278163 Which is used in he _SPI_plan struct in src/include/executor/spi_priv.h: typedef struct _SPI_plan { int magic; ... } What is its purpose? Thank you. Marcelo

Logging queries executed by SPI_execute

2025-02-02 Thread Marcelo Fernandes
Hi there, I have been trying to debug what queries an extension is firing. After reading the code for the extension, I noticed that all the statements are fired via the SPI interface, most specifically, using the SPI_execute* family of functions. However, the problem is that these statements don'