1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 23:28:02 +00:00

Add Duplicate A Local Database as a postgres til

This commit is contained in:
jbranchaud
2020-05-14 12:18:54 -05:00
parent 24d8fb005e
commit ac18c20fa8
2 changed files with 18 additions and 1 deletions

View File

@@ -0,0 +1,16 @@
# Duplicate A Local Database
You can quickly create a new database instance that is a duplicate of another
database. If the existing database is local, you don't need to dump and
restore. Instead you can use the `createdb` command that comes with Postgres:
```bash
$ createdb -O ownername -T originaldb newdb
```
This creates a new database called `newdb` using `originaldb` as a template
(`-T`). This will include the entire schema and data of the original database.
The `-O` flag allows you to specify the owner of the database. Since this is
local, you probably want your primary unix user as the owner.
[source](https://stackoverflow.com/a/6739995/535590)