- Install dependency
Open Terminal and execute the following commands: - Add PostgreSQL 9.3 repository
Before installing PostgreSQL 9.3, we have to add the PostgreSQL repository where the packages are located.
Setup key:Setup repository:
Run the following command and note down the output. It is the codename of your Ubuntu release.Replace the codename in the below command with the one you got from above command and run:
1sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ codename-pgdg main" >> /etc/apt/sources.list.d/postgresql.list' - Install PostgreSQL 9.3 using aptitude
- Accessing Database from Terminal
Installation of PostgreSQL will automatically create a Unix/Ubuntu user, namedpostgres. We will have to login with this user in order to perform various database activities such as accessing database, taking and restoring backups, starting/stopping server etc.
We may need to reset the password for postgres user before we are able to login to that account.The UNIX user, postgres is locked by default. Changing the password for this user will unlock the account. It is not preferred and even considered as a serious security threat.
To start with PostgreSQL, you can connect to the default database using the following command:
For other activities like taking data base dump, you have to login as postgres UNIX user as shown below(assuming you have root user privileges):
- Accessing Database from pgAdmin
Just like the Unix user, PostgreSQL will also create a database user named postgres, which we should use for login to database for the first time.
To be able to access database from pgAgent3, we should follow either one of the following two options:- Change the password for the postgres DB user
- Change the database access rights in the pg_hba.conf file
We will proceed with the second method, since setting password for postgres DB user is not preferred.
- After loging into postgres DB in terminal, run the following command to get the path to your pg_hba.conf file
In my case it returned: /etc/postgresql/9.3/main/pg_hba.conf
- Open the file using any text editors
And replace the two lines mentioned below:
to
And
to
If you are not able to find any lines similar to above two lines, adding the substitute lines at the top of the file will also do the job.
- Restart PostgreSQL server once.
sudo /etc/init.d/postgresql stop
sudo /etc/init.d/postgresql start
If you want more information about the pg_hba.conf file and its contents, you can read it here or here.
- That’s it! You’ve installed PostgreSQL 9.3 on Ubuntu and now you can use pgAdmin3 to login to your database with any password.
转自:http://technobytz.com/install-postgresql-9-3-ubuntu.html
cyper的笔记:
sudo -u postgres psql的意思是做为一个sudoer,我(当前为cyper)切换到用户postgres下执行psql命令(PostgreSQL的命令行程序),
执行的结果如下:
cyper@cyper-pc:~$ sudo -u postgres psql
psql (9.3.5)
Type "help" for help.
postgres=# \q
输入\q退出postgresql命令行提示符并切回当前用户(cyper)
2.我没有找到这行
local all all md5
我找到了两行以host开始以md5结尾的,我把那两个md5替换成了trust如下:
暂时没有发现任何问题
3.文中提到了不要修改postgres的密码
(这个用户默认是被锁定的,不修改密码就不会激活这个用户,但是本地的sudoers可以执行postgres+任意密码来使用该数据库)
继续阅读这里:http://blog.sina.com.cn/s/blog_6af33caa0100ypck.html