FreeBSD: Install PostgreSQL Server & Client
$ sudo pkg update
2.Search PostgreSQL in PKG.
$ pkg search postgresql
3.Install the last version PostgreSQL.
$ sudo pkg install postgresql10-server
Sample Output:
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 5 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
postgresql10-server: 10.1
libxml2: 2.9.4
postgresql10-client: 10.1
perl5: 5.24.3
readline: 7.0.3
Number of packages to be installed: 5
The process will require 88 MiB more space.
21 MiB to be downloaded.
Proceed with this action? [y/N]: y
[1/5] Fetching postgresql10-server-10.1.txz: 100% 4 MiB 4.1MB/s 00:01
[2/5] Fetching libxml2-2.9.4.txz: 100% 802 KiB 820.8kB/s 00:01
[3/5] Fetching postgresql10-client-10.1.txz: 100% 2 MiB 2.6MB/s 00:01
[4/5] Fetching perl5-5.24.3.txz: 100% 13 MiB 14.0MB/s 00:01
[5/5] Fetching readline-7.0.3.txz: 100% 334 KiB 342.1kB/s 00:01
Checking integrity... done (0 conflicting)
[1/5] Installing perl5-5.24.3...
[1/5] Extracting perl5-5.24.3: 100%
[2/5] Installing readline-7.0.3...
[2/5] Extracting readline-7.0.3: 100%
[3/5] Installing libxml2-2.9.4...
[3/5] Extracting libxml2-2.9.4: 100%
[4/5] Installing postgresql10-client-10.1...
[4/5] Extracting postgresql10-client-10.1: 100%
[5/5] Installing postgresql10-server-10.1...
===> Creating groups.
Creating group 'postgres' with gid '770'.
===> Creating users
Creating user 'postgres' with uid '770'.
=========== BACKUP YOUR DATA! =============
As always, backup your data before
upgrading. If the upgrade leads to a higher
minor revision (e.g. 8.3.x -> 8.4), a dump
and restore of all databases is
required. This is *NOT* done by the port!
===========================================
Extracting postgresql10-server-10.1: 100%
Message from perl5-5.24.3:
The /usr/bin/perl symlink has been removed starting with Perl 5.20.
For shebangs, you should either use:
#!/usr/local/bin/perl
or
#!/usr/bin/env perl
The first one will only work if you have a /usr/local/bin/perl,
the second will work as long as perl is in PATH.
Message from postgresql10-client-10.1:
The PostgreSQL port has a collection of "side orders":
postgresql-docs
For all of the html documentation
p5-Pg
A perl5 API for client access to PostgreSQL databases.
postgresql-tcltk
If you want tcl/tk client support.
postgresql-jdbc
For Java JDBC support.
postgresql-odbc
For client access from unix applications using ODBC as access
method. Not needed to access unix PostgreSQL servers from Win32
using ODBC. See below.
ruby-postgres, py-psycopg2
For client access to PostgreSQL databases using the ruby & python
languages.
postgresql-plperl, postgresql-pltcl & postgresql-plruby
For using perl5, tcl & ruby as procedural languages.
postgresql-contrib
Lots of contributed utilities, postgresql functions and
datatypes. There you find pg_standby, pgcrypto and many other cool
things.
etc...
Message from postgresql10-server-10.1:
For procedural languages and postgresql functions, please note that
you might have to update them when updating the server.
If you have many tables and many clients running, consider raising
kern.maxfiles using sysctl(8), or reconfigure your kernel
appropriately.
The port is set up to use autovacuum for new databases, but you might
also want to vacuum and perhaps backup your database regularly. There
is a periodic script, /usr/local/etc/periodic/daily/502.pgsql, that
you may find useful. You can use it to backup and perform vacuum on all
databases nightly. Per default, it performs `vacuum analyze'. See the
script for instructions. For autovacuum settings, please review
~pgsql/data/postgresql.conf.
If you plan to access your PostgreSQL server using ODBC, please
consider running the SQL script /usr/local/share/postgresql/odbc.sql
to get the functions required for ODBC compliance.
Please note that if you use the rc script,
/usr/local/etc/rc.d/postgresql, to initialize the database, unicode
(UTF-8) will be used to store character data by default. Set
postgresql_initdb_flags or use login.conf settings described below to
alter this behaviour. See the start rc script for more info.
To set limits, environment stuff like locale and collation and other
things, you can set up a class in /etc/login.conf before initializing
the database. Add something similar to this to /etc/login.conf:
---
postgres:\
:lang=en_US.UTF-8:\
:setenv=LC_COLLATE=C:\
:tc=default:
---
and run `cap_mkdb /etc/login.conf'.
Then add 'postgresql_class="postgres"' to /etc/rc.conf.
======================================================================
To initialize the database, run
/usr/local/etc/rc.d/postgresql initdb
You can then start PostgreSQL by running:
/usr/local/etc/rc.d/postgresql start
For postmaster settings, see ~pgsql/data/postgresql.conf
NB. FreeBSD's PostgreSQL port logs to syslog by default
See ~pgsql/data/postgresql.conf for more info
======================================================================
To run PostgreSQL at startup, add
'postgresql_enable="YES"' to /etc/rc.conf
4.Set up a class in /etc/login.conf. Add something similar to this to /etc/login.conf.
postgres:\
:lang=en_US.UTF-8:\
:setenv=LC_COLLATE=C:\
:tc=default:
5.run `cap_mkdb /etc/login.conf', Then add 'postgresql_class="postgres"' to /etc/rc.conf.
$ sudo cap_mkdb /etc/login.conf
# echo 'postgresql_class="postgres"' >> /etc/rc.conf
6.Confirm r.conf.
$ sysrc -a
7.To run PostgreSQL at startup, add 'postgresql_enable="YES"' to /etc/rc.conf.
$ sudo sysrc postgresql_enable=YES
8.To initialize the database, run
$ sudo /usr/local/etc/rc.d/postgresql initdb
Sample 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 locales
COLLATE: C
CTYPE: en_US.UTF-8
MESSAGES: en_US.UTF-8
MONETARY: en_US.UTF-8
NUMERIC: en_US.UTF-8
TIME: en_US.UTF-8
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory /var/db/postgres/data10 ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/usr/local/bin/pg_ctl -D /var/db/postgres/data10 -l logfile start
9.To start the database, run
$ sudo service postgresql start
10.Log into the pgsql account created for you when you installed PostgreSQL.
$ sudo passwd postgres
$ su - postgres
11.You can now enter the PostgreSQL shell using the following command.
$ psql -h host -U user -d dbname
•\du: List of roles.•\d: List of relations.
•\l: List of databases.
•\q: Quit.
12.Create a PostgreSQL user account. Supply the -s flag if you want the user to be a superuser. The -P flag will prompt you for a password
$ createuser -sdrP admin
The meaning of the parameters are as follows.
•s: This user will be superuser.
•d: This user can create new databases.
•r: This user can create new roles.
•P: Assign a password to this role.
Or You can create a new role interactively by typing:
$ createuser --interactive
switch to PostgreSQL shell using psql command. If there is no password for the user, provide the password of the newly created account:
ALTER USER new_user WITH ENCRYPTED PASSWORD 'password';
Now grant all privileges of the database to the newly created user by running the query:
GRANT ALL PRIVILEGES ON DATABASE new_db TO new_user;
13.Create a database suppling the owner of the database.
$ createdb newdb -O admin
14.Enable Remote Connections and Password Authentications
$ vi /var/db/postgres/data10/postgresql.conf
•Uncomment listen_addresses and change its value from localhost to *.
$ vi /var/db/postgres/data10/pg_hba.conf
•Change the method of authentication from trust to md5 for host type connection
# IPv4 local connections:
...
host all all 192.168.0.0/16 md5
Or
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 md5
Comments
Post a Comment