Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SOLVED] How to rename PostgreSQL database using psql CLI? #80

Closed
nelsonic opened this issue Jan 23, 2022 · 1 comment
Closed

[SOLVED] How to rename PostgreSQL database using psql CLI? #80

nelsonic opened this issue Jan 23, 2022 · 1 comment
Assignees
Labels
chore a tedious but necessary task often paying technical debt priority-3 Third priority. Considered "Nice to Have". Not urgent. technical A technical issue that requires understanding of the code, infrastructure or dependencies

Comments

@nelsonic
Copy link
Member

At present I have a Postgres database on my localhost that I don't want to DROP,
but I want to start again from scratch for dwyl/auth#174 ...
So I want to rename the auth_dev database so I can re-use that name. 💭

This should be a 1 minute task. But I want to record it somewhere in case I need to do it again.

@nelsonic nelsonic added technical A technical issue that requires understanding of the code, infrastructure or dependencies chore a tedious but necessary task often paying technical debt labels Jan 23, 2022
@nelsonic nelsonic self-assigned this Jan 23, 2022
@nelsonic nelsonic added the priority-3 Third priority. Considered "Nice to Have". Not urgent. label Jan 23, 2022
@nelsonic nelsonic changed the title psql command to rename PostgreSQL database? How to rename PostgreSQL database using psql CLI? Jan 23, 2022
@nelsonic
Copy link
Member Author

Indeed this was 1 min of googling to refresh memory ...
The ALTER command is what we're looking for: https://www.postgresql.org/docs/current/sql-alterdatabase.html

In a terminal window on Mac/Linux type: psql to start the Postgres CLI.
image

List the databases: \l (that's a backslash and lowercase "L"):

image

Rename:

The command to alter the name of the database is:

ALTER DATABASE db RENAME TO newdb;

In my case it was:

ALTER DATABASE auth_dev RENAME TO auth_dev_archive;

image

Looks like it worked:

image

Useful/relevant tutorial:

@nelsonic nelsonic changed the title How to rename PostgreSQL database using psql CLI? [SOLVED] How to rename PostgreSQL database using psql CLI? Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore a tedious but necessary task often paying technical debt priority-3 Third priority. Considered "Nice to Have". Not urgent. technical A technical issue that requires understanding of the code, infrastructure or dependencies
Projects
None yet
Development

No branches or pull requests

1 participant