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'