Install Postgresql in Fedora 16

Install postgresql

1.  #yum install postgresql postgresql-server

or if you using source

#rpm -uVh postgresql-xxx.rpm

2. start service postgre

#service postgresql start

if you got an error like ” Job failed. See system logs and ‘systemctl status’ for details ” do

#su – postgres -c “PGDATA=/var/lib/pgsql/data initdb”

output :

The files belonging to this database system will be owned by user “postgres”.
This user must also own the server process.

The database cluster will be initialized with locale en_US.UTF-8.
The default database encoding has accordingly been set to UTF8.
The default text search configuration will be set to “english”.

fixing permissions on existing directory /var/lib/pgsql/data … ok
creating subdirectories … ok
selecting default max_connections … 100
selecting default shared_buffers … 24MB
creating configuration files … ok
creating template1 database in /var/lib/pgsql/data/base/1 … ok
initializing pg_authid … ok
initializing dependencies … ok
creating system views … ok
loading system objects’ descriptions … ok
creating collations … ok
creating conversions … ok
creating dictionaries … ok
setting privileges on built-in objects … ok
creating information schema … ok
loading PL/pgSQL server-side language … ok
vacuuming database template1 … ok
copying template1 to template0 … ok
copying template1 to postgres … ok

WARNING: enabling “trust” authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.

Success. You can now start the database server using:

postgres -D /var/lib/pgsql/data
or
pg_ctl -D /var/lib/pgsql/data -l logfile start

and then do #service postgresql start

its done.

3. Check proses

#ps -ef | grep postgresql

– Setting password user admin postgres

1. #su – postgres  << enter bash shell
-bash-4.2$ psql template1  << enter active postgre mode
psql (9.1.4)
Type “help” for help.

template1=# ALTER USER postgres WITH PASSWORD ‘root’;  <<< sett password with ‘root’
ALTER ROLE
template1=# :\q << quit or exit mode
-bash-4.2$ exit
logout

2. Edit configuration file /var/lib/pgsql/data/pg_hba.conf

# TYPE DATABASE USER ADDRESS METHOD

# “local” is for Unix domain socket connections only
local all all password << to allow all user using password
# IPv4 local connections:
host all all 127.0.0.1/32 password
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres trust
#host replication postgres 127.0.0.1/32 trust
#host replication postgres ::1/128 trust

3. Restart service

#service postgresql restart

– Create User

$createuser root -P -U postgres
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
Password:

– Create database

$createdb test -U root

Password:

dec:

test : database name

-U : option for user

root : user name

– Access database

$psql -U root test
Password for user root:
psql (9.1.4)
Type “help” for help.

test=>

example query

test=> create table employee (Name char(20),Dept char(20),jobTitle char(20));
CREATE TABLE
test=> insert into employee values (‘Fred’,’IT’,’sys admin’);
INSERT 0 1
test=> insert into employee values (‘will’,’IT’,’programer’);
INSERT 0 1
test=> insert into employee values (‘mark’,’IT’,’analys’);
INSERT 0 1
test=> select * from employee;
name | dept | jobtitle
———————-+———————-+———————-
Fred                      | IT                           | sys admin
will                        | IT                           | programer
mark                      | IT                          | analys
(3 rows)

references :

http://www.yolinux.com/TUTORIALS/LinuxTutorialPostgreSQL.html

http://dev.xbata.com/database/memulai-database-postgresql

http://www.unixmen.com/postgresql-binsystemctl-initdb-postgresql-service-unknown-operation-initdb-solved/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s