mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 15:18:01 +00:00
Add Include Multiple Tables In A pg_dump as a Postgres TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1217 TILs and counting..._
|
_1218 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -612,6 +612,7 @@ _1217 TILs and counting..._
|
|||||||
- [Group By The Result Of A Function Call](postgres/group-by-the-result-of-a-function-call.md)
|
- [Group By The Result Of A Function Call](postgres/group-by-the-result-of-a-function-call.md)
|
||||||
- [Idempotent Inserts](postgres/idempotent-inserts.md)
|
- [Idempotent Inserts](postgres/idempotent-inserts.md)
|
||||||
- [Include All Queries In The Log File](postgres/include-all-queries-in-the-log-file.md)
|
- [Include All Queries In The Log File](postgres/include-all-queries-in-the-log-file.md)
|
||||||
|
- [Include Multiple Tables In A pg_dump](postgres/include-multiple-tables-in-a-pg-dump.md)
|
||||||
- [Insert A Bunch Of Records With Generate Series](postgres/insert-a-bunch-of-records-with-generate-series.md)
|
- [Insert A Bunch Of Records With Generate Series](postgres/insert-a-bunch-of-records-with-generate-series.md)
|
||||||
- [Insert Just The Defaults](postgres/insert-just-the-defaults.md)
|
- [Insert Just The Defaults](postgres/insert-just-the-defaults.md)
|
||||||
- [Inspect Progress Of Long-Running Create Index](postgres/inspect-progress-of-long-running-create-index.md)
|
- [Inspect Progress Of Long-Running Create Index](postgres/inspect-progress-of-long-running-create-index.md)
|
||||||
|
|||||||
26
postgres/include-multiple-tables-in-a-pg-dump.md
Normal file
26
postgres/include-multiple-tables-in-a-pg-dump.md
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# Include Multiple Tables In A pg_dump
|
||||||
|
|
||||||
|
When the `pg_dump` command is given the `-t` flag, it will dump just the table
|
||||||
|
named with that flag. If you want to include multiple tables in the dump, you
|
||||||
|
just need to use the flag multiple times.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ pg_dump -t users -t users_roles -t roles my_database > roles.dump.sql
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, you can specify a
|
||||||
|
[pattern](https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-PATTERNS)
|
||||||
|
when using the `-t` flag.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ pg_dump -t 'users*|roles' my_database > roles.dump.sql
|
||||||
|
```
|
||||||
|
|
||||||
|
You have to be a little more mindful of what will and won't be included when
|
||||||
|
crafting a pattern. It is a nice shortcut for a well-known or well-constrained
|
||||||
|
data model.
|
||||||
|
|
||||||
|
See the [`pg_dump`
|
||||||
|
docs](https://www.postgresql.org/docs/current/app-pgdump.html) for more
|
||||||
|
details, as well as [some
|
||||||
|
examples](https://www.postgresql.org/docs/current/app-pgdump.html#PG-DUMP-EXAMPLES).
|
||||||
Reference in New Issue
Block a user