Skip to content

Conversation

sudo-dliberty-eiq
Copy link

The MAINTAIN privilege was added in Postgres 17.
https://www.postgresql.org/docs/17/ddl-priv.html

This change adds support for users on Postgres 17, however, opening up means users of this provider attempting to add MAINTAIN permissions on databases <= 17 will get an error.

This change addresses this issue:
#506

This pull request includes changes to the postgresql/helpers.go and postgresql/helpers_test.go files to add the new "MAINTAIN" privilege for tables. The most important changes are as follows:

Privileges update:

Test updates:

@chafouin
Copy link

chafouin commented Apr 7, 2025

Hello ! Do you think it would be possible to get a release of the provider soon with this PR merged ? That would help us to get unblocked as we are trying to add the MAINTAIN to permission to some of our users. Thanks !

@yakloinsteak
Copy link

I needed this fix as well, but though it now is able to apply MAINTAIN, if you run a plan after that, it seems that postgres has "expanded" this into individual permissions, so you're forever out of sync, oscillating between MAINTAIN and that set.

This is what happens. It either wants to do this or add the MAINTAIN priv.

~ privileges        = [
    - "MAINTAIN",
    + "DELETE",
    + "INSERT",
    + "REFERENCES",
    + "SELECT",
    + "TRIGGER",
    + "TRUNCATE",
    + "UPDATE",
  ]

I think the fix might need to account for this, but I haven't done a lot of testing. I'm going to replace all of our MAINTAINs with this set and move on, though supporting this priv would be nice.

@ooaklee
Copy link

ooaklee commented May 13, 2025

Any update on this?

@sudo-dliberty-eiq
Copy link
Author

Just waiting on approval to merge by a reviewer with write access

@mohammedelnabawy
Copy link

Any update on this?

@lsowen
Copy link

lsowen commented Jul 10, 2025

@cyrilgdn would you be able to review this change?

@mr-andres-carvajal
Copy link

I needed this fix as well, but though it now is able to apply MAINTAIN, if you run a plan after that, it seems that postgres has "expanded" this into individual permissions, so you're forever out of sync, oscillating between MAINTAIN and that set.

This is what happens. It either wants to do this or add the MAINTAIN priv.

~ privileges        = [
    - "MAINTAIN",
    + "DELETE",
    + "INSERT",
    + "REFERENCES",
    + "SELECT",
    + "TRIGGER",
    + "TRUNCATE",
    + "UPDATE",
  ]

I think the fix might need to account for this, but I haven't done a lot of testing. I'm going to replace all of our MAINTAINs with this set and move on, though supporting this priv would be nice.

I assume this will need investigating before merging?

@logan-hcg
Copy link

I don't see the "expanded permissions" issue mentioned above when running against a postgres 17 server.

@msdousti24
Copy link

I closed my PR as a duplicate of this.

Just for further details, quoting what I wrote there:

The MAINTAIN privilege is added in Postgres 17 (see here). Without it, even the owner of the table cannot perform tasks like VACUUM, ANALYZE, or REINDEX.

Upon adding this privilege, we got this error:

Error: MAINTAIN is not an allowed privilege for object type table

Upon a closer investigation, the list of table privileges in allowedPrivileges needs to be augmented.

The following query on Postgres 17 shows all valid privileges for different types of Postgres objects:

with t(col) as (
select string_to_table('cdfFlLnprsStT', null)
)
select col as object_type, array_agg(privilege_type) as privileges
from t
join lateral aclexplode(acldefault(col::"char", 0)) as a on true
group by 1
order by 1;

Result:
image

@manish-hashicorp
Copy link

Hello, I also need this. Please merge and release if possible. Really appreciate this project. Thanks!

@chafouin
Copy link

chafouin commented Sep 4, 2025

@cyrilgdn I saw you made a release recently, would it be possible to review/merge this PR and make another release please ? Thanks 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.