PostgreSQL & PHP Tutorials - PostgreSQL Users

PostgreSQL »  PostgreSQL Users
PostgreSQL »  Starting Out »  PostgreSQL Users

Posted By Chris Smith Posted on 07 Feb 2006, 09:21 PM
PostgreSQL supports user accounts to keep data separate. Here's a quick look at creating them to keep things secure.    To create a user it's quite simple. PostgreSQL has a command to do all the work for you.

$ /usr/local/pgsql/bin/createuser -P

The '-P' means prompt for a password. You can then follow the prompts.

If you prefer, you can specify more options and create the user all at once.

Check

$ /usr/local/pgsql/bin/createuser --help

for more options.

I created a 'tomcat' user (since that's my primary login):

$ /usr/local/pgsql/bin/createuser -P -a -d tomcat

and entered a password.

This new user can create other users and new databases, it's effectively the same as the 'postgres' user - so make sure you keep the password secure!

Now, if you log back in as our primary user (in my case 'tomcat'), you can create a new user and a new database - this saves a lot of hassle of changing to a different system user, and also stops the database administrator from needing root access to the server.

Since you're logged in to the as 'tomcat' and not the 'postgres' user, when you create a new user, you'll get prompted for your password.

You can follow the same procedure for creating another user for later projects.

To remove a user, it's quite simple:
$ /usr/local/pgsql/bin/dropuser <username>

If you try to drop a user that owns a database, then PostgreSQL will alert you to the problem and stop you from deleting that user:

$ /usr/local/pgsql/bin/dropuser contacts
dropuser: removal of user "contacts" failed: ERROR: user "contacts" cannot be dropped
DETAIL: The user owns database "contacts".
Avg Rating: 0
Vote Count: 0

              


Want to post a comment? Fill in the details below.

Your Name  : 
Your Email  : 
Your Website  : 
Spam Check! Please answer this question  : 4 + 6 =
Comment