You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The postgresql_table command shows spurious change status (and attempts unnecessary ALTER TABLE...OWNER TO) when multiple schemas have tables of the same name (which is the table being operated on by the task).
This happens because the query to get the existing information does not properly limit by schema name for the pg_tables view. It only limits for the pg_namespace part of the query. As a result, this query returns multiple rows, one per schema containing a table of the specified name.
Use the postgresql_table (e.g. in a loop) to create multiple tables of the same name in different schemas.
Run the task again.
In our case, the actual task looks like this, where pbx_instances is a dictionary in the inventory where the keys are strings, e.g. office and krls-pbx2 and pbx_freeswitch_database_username is freeswitch.
Note how it thinks the owner is freeswitch_krls_pbx2, when it's actually already freeswitch_office.
I did not actually test this reproducer in an empty database. Depending on the order of the rows in PostgreSQL's internal tables, it's possible this will reproduce in the opposite way (i.e. "office" will show no change but "krls_pbx2" will show a change.)
The text was updated successfully, but these errors were encountered:
rlaager
added a commit
to wiktel/community.postgresql
that referenced
this issue
Mar 27, 2025
…ions#817)
When checking to see if an table exists, the schema name needs to be
taken into account. That is, the same name can exist in multiple
schemas.
Fixesansible-collections#817
rlaager
added a commit
to wiktel/community.postgresql
that referenced
this issue
Apr 1, 2025
…ions#817)
When checking to see if an table exists, the schema name needs to be
taken into account. That is, the same name can exist in multiple
schemas.
Fixesansible-collections#817
SUMMARY
The
postgresql_table
command shows spurious change status (and attempts unnecessaryALTER TABLE...OWNER TO
) when multiple schemas have tables of the same name (which is the table being operated on by the task).This happens because the query to get the existing information does not properly limit by schema name for the
pg_tables
view. It only limits for thepg_namespace
part of the query. As a result, this query returns multiple rows, one per schema containing a table of the specified name.community.postgresql/plugins/modules/postgresql_table.py
Lines 300 to 305 in 1317e05
The fix is trivial (adjust to your line wrapping, etc. taste):
ISSUE TYPE
COMPONENT NAME
postgresql_table
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
The target OS is Debian 12 with PostgreSQL 15.
STEPS TO REPRODUCE
postgresql_table
(e.g. in a loop) to create multiple tables of the same name in different schemas.In our case, the actual task looks like this, where
pbx_instances
is a dictionary in the inventory where the keys are strings, e.g.office
andkrls-pbx2
andpbx_freeswitch_database_username
isfreeswitch
.If we eliminate the variables for simplicity, and add tasks to create the pre-requisite users/roles and schemas, we get this:
EXPECTED RESULTS
The task should not try to do anything (i.e. not try to run any SQL) and should not show a changed status.
ACTUAL RESULTS
On the second run, for all but one of the schemas (whichever one the pg_table query lists first):
Note how it thinks the owner is
freeswitch_krls_pbx2
, when it's actually alreadyfreeswitch_office
.I did not actually test this reproducer in an empty database. Depending on the order of the rows in PostgreSQL's internal tables, it's possible this will reproduce in the opposite way (i.e. "office" will show no change but "krls_pbx2" will show a change.)
The text was updated successfully, but these errors were encountered: