The PostgresStorageNode is a multi-user node. That is, multiple AtomSpaces can all open up the same Postgres database at the same time, stuff atoms into it, read them out, delete them, and so on. Because Postgres is distributed and scalable, one could have, in principle, thousands of AtomSpaces doing this all at the same time. In practice, no one has ever tried doing this with more than three AtomSpaces at once (to the best of my knowledge. World record holders are invited to update this wiki page.) It is, of course, up to you to make sure that all these instances are not stepping on one-another.
Here's a very short example that opens a connection to a Postgres database, and fetches all of the Values attached to a given Atom.
(define psn (PostgresStorageNode "postgres://opencog_tester:firstname.lastname@example.org/opencog_test")) (cog-open psn) (fetch-atom (Concept "foo") psn) (cog-close psn)
The URL encodes the username opencog_tester, the password cheese, the name of the database opencog_test and the hostname localhost. That is, URL has the generic format
The username, password and hostname are optional; if not specified, defaults will be obtained from the environment, according to the conventional Postgres configuration rules. Thus, depending on the configuration, the following URL's should work as well:
The last form assumes localhost aka 127.0.0.1.
Earlier versions also supported odbc:// URL's, but this has been removed because ODBC is a real pain-in-the-neck to configure, and is 2x slower than the native Postgres API.
Setting up and configuring Postgres for use with the AtomSpace is rather complex. See the Configuring PostgreSQL wiki page for how to do this. Most users will be happier with RocksStorageNode, which does not require any configuration; it just writes to the local filesystem. it is also roughly 4x or 8x faster than PostrgresStorageNode.