{
    "content": [
        {
            "type": "text",
            "text": "# ALTER_DATABASE(7) (man)\n\n**Summary:** ALTERDATABASE - change a database\n\n**Synopsis:** ALTER DATABASE name [ [ WITH ] option [ ... ] ]\nwhere option can be:\nALLOWCONNECTIONS allowconn\nCONNECTION LIMIT connlimit\nISTEMPLATE istemplate\nALTER DATABASE name RENAME TO newname\nALTER DATABASE name OWNER TO { newowner | CURRENTROLE | CURRENTUSER | SESSIONUSER }\nALTER DATABASE name SET TABLESPACE newtablespace\nALTER DATABASE name SET configurationparameter { TO | = } { value | DEFAULT }\nALTER DATABASE name SET configurationparameter FROM CURRENT\nALTER DATABASE name RESET configurationparameter\nALTER DATABASE name RESET ALL\n\n## Examples\n\n- `To disable index scans by default in the database test:`\n- `ALTER DATABASE test SET enableindexscan TO off;`\n\n## See Also\n\n- CREATEDATABASE(7)\n- DROPDATABASE(7)\n- SET(7)\n- CREATETABLESPACE(7)\n- DATABASE(7)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (19 lines)\n- **DESCRIPTION** (27 lines)\n- **PARAMETERS** (34 lines)\n- **NOTES** (4 lines)\n- **EXAMPLES** (4 lines)\n- **COMPATIBILITY** (2 lines)\n- **SEE ALSO** (6 lines)\n\n## Full Content\n\n### NAME\n\nALTERDATABASE - change a database\n\n### SYNOPSIS\n\nALTER DATABASE name [ [ WITH ] option [ ... ] ]\n\nwhere option can be:\n\nALLOWCONNECTIONS allowconn\nCONNECTION LIMIT connlimit\nISTEMPLATE istemplate\n\nALTER DATABASE name RENAME TO newname\n\nALTER DATABASE name OWNER TO { newowner | CURRENTROLE | CURRENTUSER | SESSIONUSER }\n\nALTER DATABASE name SET TABLESPACE newtablespace\n\nALTER DATABASE name SET configurationparameter { TO | = } { value | DEFAULT }\nALTER DATABASE name SET configurationparameter FROM CURRENT\nALTER DATABASE name RESET configurationparameter\nALTER DATABASE name RESET ALL\n\n### DESCRIPTION\n\nALTER DATABASE changes the attributes of a database.\n\nThe first form changes certain per-database settings. (See below for details.) Only the\ndatabase owner or a superuser can change these settings.\n\nThe second form changes the name of the database. Only the database owner or a superuser can\nrename a database; non-superuser owners must also have the CREATEDB privilege. The current\ndatabase cannot be renamed. (Connect to a different database if you need to do that.)\n\nThe third form changes the owner of the database. To alter the owner, you must own the\ndatabase and also be a direct or indirect member of the new owning role, and you must have\nthe CREATEDB privilege. (Note that superusers have all these privileges automatically.)\n\nThe fourth form changes the default tablespace of the database. Only the database owner or a\nsuperuser can do this; you must also have create privilege for the new tablespace. This\ncommand physically moves any tables or indexes in the database's old default tablespace to\nthe new tablespace. The new default tablespace must be empty for this database, and no one\ncan be connected to the database. Tables and indexes in non-default tablespaces are\nunaffected.\n\nThe remaining forms change the session default for a run-time configuration variable for a\nPostgreSQL database. Whenever a new session is subsequently started in that database, the\nspecified value becomes the session default value. The database-specific default overrides\nwhatever setting is present in postgresql.conf or has been received from the postgres command\nline. Only the database owner or a superuser can change the session defaults for a database.\nCertain variables cannot be set this way, or can only be set by a superuser.\n\n### PARAMETERS\n\nname\nThe name of the database whose attributes are to be altered.\n\nallowconn\nIf false then no one can connect to this database.\n\nconnlimit\nHow many concurrent connections can be made to this database. -1 means no limit.\n\nistemplate\nIf true, then this database can be cloned by any user with CREATEDB privileges; if false,\nthen only superusers or the owner of the database can clone it.\n\nnewname\nThe new name of the database.\n\nnewowner\nThe new owner of the database.\n\nnewtablespace\nThe new default tablespace of the database.\n\nThis form of the command cannot be executed inside a transaction block.\n\nconfigurationparameter\nvalue\nSet this database's session default for the specified configuration parameter to the\ngiven value. If value is DEFAULT or, equivalently, RESET is used, the database-specific\nsetting is removed, so the system-wide default setting will be inherited in new sessions.\nUse RESET ALL to clear all database-specific settings.  SET FROM CURRENT saves the\nsession's current value of the parameter as the database-specific value.\n\nSee SET(7) and Chapter 20 for more information about allowed parameter names and values.\n\n### NOTES\n\nIt is also possible to tie a session default to a specific role rather than to a database;\nsee ALTER ROLE (ALTERROLE(7)). Role-specific settings override database-specific ones if\nthere is a conflict.\n\n### EXAMPLES\n\nTo disable index scans by default in the database test:\n\nALTER DATABASE test SET enableindexscan TO off;\n\n### COMPATIBILITY\n\nThe ALTER DATABASE statement is a PostgreSQL extension.\n\n### SEE ALSO\n\nCREATE DATABASE (CREATEDATABASE(7)), DROP DATABASE (DROPDATABASE(7)), SET(7), CREATE\nTABLESPACE (CREATETABLESPACE(7))\n\n\n\nPostgreSQL 14.23                                2026                               ALTER DATABASE(7)\n\n"
        }
    ],
    "structuredContent": {
        "command": "ALTER_DATABASE",
        "section": "7",
        "mode": "man",
        "summary": "ALTERDATABASE - change a database",
        "synopsis": "ALTER DATABASE name [ [ WITH ] option [ ... ] ]\nwhere option can be:\nALLOWCONNECTIONS allowconn\nCONNECTION LIMIT connlimit\nISTEMPLATE istemplate\nALTER DATABASE name RENAME TO newname\nALTER DATABASE name OWNER TO { newowner | CURRENTROLE | CURRENTUSER | SESSIONUSER }\nALTER DATABASE name SET TABLESPACE newtablespace\nALTER DATABASE name SET configurationparameter { TO | = } { value | DEFAULT }\nALTER DATABASE name SET configurationparameter FROM CURRENT\nALTER DATABASE name RESET configurationparameter\nALTER DATABASE name RESET ALL",
        "flags": [],
        "examples": [
            "To disable index scans by default in the database test:",
            "ALTER DATABASE test SET enableindexscan TO off;"
        ],
        "see_also": [
            {
                "name": "CREATEDATABASE",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/CREATEDATABASE/7/json"
            },
            {
                "name": "DROPDATABASE",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/DROPDATABASE/7/json"
            },
            {
                "name": "SET",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/SET/7/json"
            },
            {
                "name": "CREATETABLESPACE",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/CREATETABLESPACE/7/json"
            },
            {
                "name": "DATABASE",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/DATABASE/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 19,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 27,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 34,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 6,
                "subsections": []
            }
        ]
    }
}