This repository has been archived by the owner on Dec 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 87
add doc on dumping postgresql data locally #803
Open
jtotoole
wants to merge
1
commit into
master
Choose a base branch
from
jot-pgdump-doc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,8 @@ Given that behind the scenes a container is just a fancy chroot, it wouldn't mak | |
|
||
## Run `psql` | ||
|
||
To access PostgreSQL directly, you can either run `psql` in a `postgresql-server` container, or map the port from a PostgreSQL container to your host machine and access it from there: | ||
To access PostgreSQL directly, you can either run `psql` in a `postgresql-server` container, or map the port from a PostgreSQL container to your host machine and access it from there. At present, Media Cloud | ||
runs our PostgreSQL server [on `woodward`](https://github.com/mediacloud/production-docker-config/blob/master/hosts.yml#L69-L70); you can also access PostgreSQL data by `ssh`ing to `bd-postgresql.srv.mediacloud.org`. | ||
|
||
* To run **`psql` in PostgreSQL container**: | ||
|
||
|
@@ -152,3 +153,25 @@ To access PostgreSQL directly, you can either run `psql` in a `postgresql-server | |
|
||
mediacloud=# | ||
``` | ||
|
||
* To **dump PostgreSQL tables to your host machine**: | ||
|
||
1. `ssh` to the server running PostgreSQL and find its container ID, as described above. | ||
|
||
2. Choose the table you want and dump it as a `.sql` file with the following syntax: | ||
|
||
```docker exec 123somecontainer456 pg_dump --table=media > media.sql` | ||
|
||
Note that there are certain tables (e.g. `story_sentences`) that are so large as to be infeasible | ||
to work with locally. You can check that by running `du` on the dumped `.sql` file while `ssh`ed | ||
into the server, e.g. `du media.sql --block-size=1MB`. | ||
|
||
3. Copy the `.sql` file to a directory on your host machine via `scp`, e.g. | ||
|
||
```scp [email protected]:/nfs/home/james/media.sql ./``` | ||
|
||
4. Load the `.sql` file to the local database of your choice. For example, if you want to use | ||
PostgreSQL, create a database, connect to it via `psql` and load the table with a | ||
command along the lines of | ||
|
||
```mediacloud=# \i '/home/james/mediacloud/sql_dumps/media.sql'``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that this only worked when I omitted the
-it
flags