<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://morison.biz/technotes/feeds/rss.css" ?>
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/" 
	xmlns:dc="http://purl.org/dc/elements/1.1/" 
	xmlns:icbm="http://postneo.com/icbm/" 
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/" 
	xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" 
	xmlns:wfw="http://wellformedweb.org/CommentAPI/" >

<channel>
	<title>Comments for: PostgreSQL 1A</title>
	<link>http://morison.biz/technotes/articles/56</link>
	<description>I spent the last 8 years on a lot of MySQL and little MSSQL. Now, I'm on a PostgreSQL project. Here's my cheat sheet of DBMS specific commands I needed to figure out right away.

Install on Ubuntu 8.10
$ sudo apt-get install postgresql-8.3 postgresql-server-dev-8.3
$ sudo vi /etc/postgresql/8.3/main/postgresql.conf 
# uncomment the listen_addresses = 'localhost' line
# optional: change localhost to machine hostaddr if you want outside access
$ sudo /etc/init.d/postgresql-8.3 restart
Give the &quot;root&quot; db user a password, create a new dbuser and a database with access privs for that new dbuser. Also, give the new dbuser perms to create more databases.
$ sudo -u postgres psql template1
template1=# ALTER USER postgres WITH UNENCRYPTED PASSWORD 'P8ss';
ALTER ROLE
template1=# CREATE USER user1 CREATEDB;
CREATE ROLE
template1=# ALTER USER user1 WITH UNENCRYPTED PASSWORD 'P9ss';
ALTER ROLE
template1=# CREATE DATABASE db1 WITH OWNER user1;
CREATE DATABASE
template1=# q
To suck a sqldump into that database
$ zcat /PathToDbDump/DbDump.sql.gz | psql -h localhost -U postgres -d user1
Logging in as non-postgres user (this bit baffled me originally, until I decoded the postgres init settings): /etc/postgresql/8.3/main/pg_hba.conf has security settings that say, &quot;If connected via unix socket then require the db username match the process owner name.&quot; By default psql uses the unix socket. That's fine for the &quot;root&quot; db user (postgres), but not how you want access other dbs. However, for network socket connections pg_hba.conf is set to use only password check against it's user table. Yay. So access through the socket, which is the general case in production systems anyway, as the db is on a dedicated machine.Log in as the user1 and create a db.
psql --username user1 --password -h localhost template1
CREATE DATABASE db2 WITH OWNER ...</description>
	<language>en</language>
	<copyright>2006-2008, Rod Morison Software</copyright>
	<managingEditor>technotes@morison.biz</managingEditor>
	<lastBuildDate>Wed, 08 Feb 2012 06:00:02 GMT</lastBuildDate>
	<generator>Yet Another Community System</generator>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>70</ttl>

</channel>
</rss>
