Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecates the paster commands `db load` and `db dump` in favor of PostgreSQL's `pg_dump` and `pg_restore`. `db load` and `db dump` are kept but print a warning, and their documentation is replaced with a documentation of how to dump/import the database using `pg_dump` and `pg_restore`.
- Loading branch information
Showing
13 changed files
with
207 additions
and
177 deletions.
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,171 @@ | ||
.. _database management: | ||
|
||
=================== | ||
Database Management | ||
=================== | ||
|
||
.. note:: | ||
|
||
See :doc:`paster` for details on running the ``paster`` commands | ||
mentioned below. | ||
|
||
|
||
.. _db init: | ||
|
||
Initialization | ||
-------------- | ||
|
||
Before you can run CKAN for the first time, you need to run ``db init`` to | ||
initialize your database: | ||
|
||
.. parsed-literal:: | ||
paster db init -c |production.ini| | ||
If you forget to do this you'll see this error message in your web browser: | ||
|
||
503 Service Unavailable: This site is currently off-line. Database is not | ||
initialised. | ||
|
||
|
||
.. _db clean: | ||
|
||
Cleaning | ||
-------- | ||
|
||
.. warning:: | ||
|
||
This will delete all data from your CKAN database! | ||
|
||
You can delete everything in the CKAN database, including the tables, to start | ||
from scratch: | ||
|
||
.. parsed-literal:: | ||
paster db clean -c |production.ini| | ||
After cleaning the database you must do either `initialize it`_ or `import | ||
a previously created dump`_. | ||
|
||
.. _initialize it: Initialization_ | ||
.. _import a previously created dump: `db dumping and loading`_ | ||
|
||
|
||
Import and Export | ||
----------------- | ||
|
||
.. _db dumping and loading: | ||
|
||
Dumping and Loading databases to/from a file | ||
```````````````````````````````````````````` | ||
|
||
PostgreSQL offers the command line tools pg_dump_ and pg_restore_ for dumping | ||
and restoring a database and its content to/from a file. | ||
|
||
For example, first dump your CKAN database:: | ||
|
||
sudo -u postgres pg_dump --format=custom -d ckan_default > ckan.dump | ||
|
||
.. warning:: | ||
|
||
The exported file is a complete backup of the database, and includes API | ||
keys and other user data which may be regarded as private. So keep it | ||
secure, like your database server. | ||
|
||
.. note:: | ||
|
||
If you've chosen a non-default database name (i.e. *not* ``ckan_default``) | ||
then you need to adapt the commands accordingly. | ||
|
||
Then restore it again: | ||
|
||
.. parsed-literal:: | ||
paster db clean -c |production.ini| | ||
sudo -u postgres pg_restore --clean --if-exists -d ckan_default < ckan.dump | ||
If you're importing a dump from an older version of CKAN you must :ref:`upgrade | ||
the database schema <db upgrade>` after the import. | ||
|
||
Once the import (and a potential upgrade) is complete you should :ref:`rebuild | ||
the search index <rebuild search index>`. | ||
|
||
.. note:: | ||
|
||
Earlier versions of CKAN offered the ``paster`` commands ``db dump`` and | ||
``db load``. These are still available but are deprecated in favor of | ||
the native tools of PostgreSQL mentioned above. ``db dump`` and ``db load`` | ||
will be removed in future versions of CKAN. | ||
|
||
.. _pg_dump: https://www.postgresql.org/docs/current/static/app-pgdump.html | ||
.. _pg_restore: https://www.postgresql.org/docs/current/static/app-pgrestore.html | ||
|
||
|
||
.. _datasets dump: | ||
|
||
Exporting Datasets to JSON Lines | ||
```````````````````````````````` | ||
|
||
You can export all of your CKAN site's datasets from your database to a JSON | ||
Lines file using ckanapi_: | ||
|
||
.. parsed-literal:: | ||
ckanapi dump datasets -c |production.ini| -O my_datasets.jsonl | ||
This is useful to create a simple public listing of the datasets, with no user | ||
information. Some simple additions to the Apache config can serve the dump | ||
files to users in a directory listing. To do this, add these lines to your | ||
virtual Apache config file (e.g. |apache_config_file|):: | ||
|
||
Alias /dump/ /home/okfn/var/srvc/ckan.net/dumps/ | ||
|
||
# Disable the mod_python handler for static files | ||
<Location /dump> | ||
SetHandler None | ||
Options +Indexes | ||
</Location> | ||
|
||
.. warning:: | ||
|
||
Don't serve an SQL dump of your database (created using the ``pg_dump`` | ||
command), as those contain private user information such as email | ||
addresses and API keys. | ||
|
||
.. _ckanapi: https://github.com/ckan/ckanapi | ||
|
||
|
||
.. _users dump: | ||
|
||
Exporting User Accounts to JSON Lines | ||
````````````````````````````````````` | ||
|
||
You can export all of your CKAN site's user accounts from your database to | ||
a JSON Lines file using ckanapi_: | ||
|
||
.. parsed-literal:: | ||
ckanapi dump users -c |production.ini| -O my_database_users.jsonl | ||
.. _db upgrade: | ||
|
||
Upgrading | ||
--------- | ||
|
||
.. warning:: | ||
|
||
You should :ref:`create a backup of your database <db dumping and loading>` | ||
before upgrading it. | ||
|
||
To avoid problems during the database upgrade, comment out any plugins | ||
that you have enabled in your ini file. You can uncomment them again when | ||
the upgrade finishes. | ||
|
||
If you are upgrading to a new CKAN :ref:`major release <releases>` update your | ||
CKAN database's schema using the ``paster db upgrade`` command: | ||
|
||
.. parsed-literal:: | ||
paster db upgrade -c |production.ini| | ||
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
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
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
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
Oops, something went wrong.