sqlx::test fails with "permission denied for table pg_namespace" #2051
-
| I've tried using the examples from the docs, using the following files: .env: test-file:     use sqlx::pool::{PoolConnection, PoolOptions};
    use sqlx::postgres::PgConnectOptions;
    use sqlx::{PgPool, Postgres};
    #[sqlx::test]
    async fn db(
        _pool_options: PoolOptions<Postgres>,
        _conn_options: PgConnectOptions,
    ) -> sqlx::Result<()> {
        Ok(())
    }
    #[sqlx::test]
    async fn pool_test(_pool: PgPool) -> sqlx::Result<()> {
        Ok(())
    }
    #[sqlx::test]
    async fn conn_test(_conn: PoolConnection<Postgres>) -> sqlx::Result<()> {
        Ok(())
    }All test-functions fail with the following message: What am I doing wrong? | 
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
| The user credentials you use with  | 
Beta Was this translation helpful? Give feedback.
-
| I created a superuser and the tests started working! Thanks! | 
Beta Was this translation helpful? Give feedback.
-
| Many cloud SQL solutions will not grant superuser roles. Most will however grant broad permissions, even to create databases. Is there a way to use  Creating a schema sounds fine for example. It could be a one-off command to run. "creating a superuser" unfortunately will be impossible for many. | 
Beta Was this translation helpful? Give feedback.
-
| I think the error message can also be improved to here to improve usability. Here is the full error message I got failed to connect to setup test database: Database(PgDatabaseError { severity: Error, code: "42501", message: "permission denied for table pg_namespace", detail: None, hint: None, position: None, where: None, schema: None, table: None, column: None, data_type: None, constraint: None, file: Some("aclchk.c"), line: Some(3650), routine: Some("aclcheck_error") }) My main issues with this error message are 2 things 
 The error message could say. "Unable to run the tests because the user 'username' does not have SUPERUSER privileges on the server 'server-name-or-ip', required to create and drop the database under test." | 
Beta Was this translation helpful? Give feedback.
The user credentials you use with
#[sqlx::test]need superuser permissions since they create and drop databases. The specific permission check that's failing there is the need for aLOCKgrant on thepg_catalog.pg_namespacetable insome_databaseas it also creates a_sqlx_testschema to host the objects it uses to track the databases it's created so it can clean them up later.