CentOS 6
Sponsored Link

Install PostgreSQL
2015/01/15
 
Install PostgreSQL to configure database server.
[1] Install PostgreSQL.
[root@www ~]#
yum -y install postgresql-server
[root@www ~]#
/etc/rc.d/init.d/postgresql initdb

Initializing database:
[ OK ]

[root@www ~]#
vi /var/lib/pgsql/data/postgresql.conf
# line 59: uncomment and change (listen all)

listen_addresses = '
*
'
# line 33: uncomment and change (change log format)

log_line_prefix = '
%t %u %d
'
[root@www ~]#
/etc/rc.d/init.d/postgresql start

Starting postgresql service:
[ OK ]

[root@www ~]#
chkconfig postgresql on
[2] Set admin user's password and add a user.
# switch to postgres user and set password

[root@www ~]#
su - postgres

-bash-4.1$
psql -c "alter user postgres with password 'password'"

ALTER ROLE
# add a user "cent"

-bash-4.1$
createuser cent

Shall the new role be a superuser? (y/n)
y
# set privileges if you want

[3] Login with a user just created and make sure basic DB operations.
# create a test DB

[cent@www ~]$
createdb testdb

[cent@www ~]$
psql -l
# confirm

                                  List of databases
   Name    |  Owner   | Encoding |  Collation  |    Ctype    |   Access privileg
es
-----------+----------+----------+-------------+-------------+------------------
-----
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
                                                             : postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
                                                             : postgres=CTc/postgres
 testdb    | cent     | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
(4 rows)

# connect to the test DB

[cent@www ~]$
psql testdb

psql (8.4.20)
Type "help" for help.
# set password

testdb=#
alter user cent with password 'password';

ALTER ROLE
# create a test table

testdb=#
create table test ( no int,name text );

CREATE TABLE
# insert test data

testdb=#
insert into test (no,name) values (1,'cent');

INSERT 0 1
# confirm

testdb=#
select * from test;
 no | name
----+-------
  1 | cent
(1 row)
# remove test table

testdb=#
drop table test;

DROP TABLE
# quit

testdb=#
\q
# remobe test DB

[cent@www ~]$
dropdb testdb
Matched Content
 
Tweet