Search This Blog

Friday, September 28, 2018

Install Postgresql 9.6 on Amazon Linux 2 by Amazon Linux Extras

Yes you can install the latest Postgresql via https://www.postgresql.org/download/linux/redhat/.

But it suppose to work on Cent OS 7 or RHEL 7.
Ammazon Linux 2 have more "Fresher" package, including the Kernel.

From Amazon Linux 2, it added Amazon Linux Extras

Extras is a mechanism in Amazon Linux 2 to enable the consumption of new versions of application software on a stable operating system that is supported until June 30, 2023.
Extras include Ansible 2.4.2, memcached 1.5, nginx 1.12, Postgresql 9.6, MariaDB 10.2, Go 1.9, Redis 4.0, R 3.4, Rust 1.22.1.

I think it is better using Extras from Amazon Linux Team. Here is how:
  1. Check the AMI version:
  2. # uname -a
    Linux ip-10-10-10-10.tal-ent.local 4.14.70-72.55.amzn2.x86_64 #1 SMP Wed Sep 19 19:09:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
    # cat /etc/system-release
    Amazon Linux 2
    # cat /etc/image-id
    image_name="amzn2-ami-hvm"
    image_version="2"
    image_arch="x86_64"
    image_file="amzn2-ami-hvm-2.0.20180810-x86_64.xfs.gpt"
    image_stamp="8008-2abd"
    image_date="20180811020321"
    recipe_name="amzn2 ami"
    recipe_id="c652686a-2415-9819-65fb-4dee-9792-289d-1e2846bd"
    
  3. Check available package in Extras:
  4. # amazon-linux-extras
      0  ansible2                 available    [ =2.4.2  =2.4.6 ]
      1  emacs                    available    [ =25.3 ]
      2  httpd_modules            available    [ =1.0 ]
      3  memcached1.5             available    [ =1.5.1 ]
      4  nginx1.12                available    [ =1.12.2 ]
      5  postgresql9.6            available    [ =9.6.6  =9.6.8 ]
      6  postgresql10             available    [ =10 ]
      8  redis4.0                 available    [ =4.0.5  =4.0.10 ]
      9  R3.4                     available    [ =3.4.3 ]
     10  rust1                    available    [ =1.22.1  =1.26.0  =1.26.1  =1.27.2 ]
     11  vim                      available    [ =8.0 ]
     12  golang1.9                available    [ =1.9.2 ]
     13  ruby2.4                  available    [ =2.4.2  =2.4.4 ]
     14  nano                     available    [ =2.9.1 ]
     15  php7.2                   available    [ =7.2.0  =7.2.4  =7.2.5  =7.2.8 ]
     16  lamp-mariadb10.2-php7.2  available    [ =10.2.10_7.2.0  =10.2.10_7.2.4  =10.2.10_7.2.5  =10.2.10_7.2.8 ]
     17  libreoffice              available    [ =5.0.6.2_15  =5.3.6.1 ]
     18  gimp                     available    [ =2.8.22 ]
     19  docker=latest            enabled      [ =17.12.1  =18.03.1  =18.06.1 ]
     20  mate-desktop1.x          available    [ =1.19.0  =1.20.0 ]
     21  GraphicsMagick1.3        available    [ =1.3.29 ]
     22  tomcat8.5                available    [ =8.5.31  =8.5.32 ]
     23  epel                     available    [ =7.11 ]
    
  5. Install postgresql 9.6
  6. # amazon-linux-extras install postgresql9.6
    Installing postgresql
    Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
    amzn2-core                                                                                                                                      | 2.4 kB  00:00:00     
    amzn2extra-docker                                                                                                                               | 1.3 kB  00:00:00     
    amzn2extra-epel                                                                                                                                 | 1.3 kB  00:00:00     
    amzn2extra-postgresql9.6                                                                                                                        | 1.3 kB  00:00:00     
    amzn2extra-postgresql9.6/2/x86_64/primary_db                                                                                                    |  23 kB  00:00:00     
    152 packages excluded due to repository priority protections
    Resolving Dependencies
    --> Running transaction check
    ---> Package postgresql.x86_64 0:9.6.8-1.amzn2.0.1 will be installed
    --> Processing Dependency: postgresql-libs(x86-64) = 9.6.8-1.amzn2.0.1 for package: postgresql-9.6.8-1.amzn2.0.1.x86_64
    --> Processing Dependency: libpq.so.5()(64bit) for package: postgresql-9.6.8-1.amzn2.0.1.x86_64
    --> Running transaction check
    ---> Package postgresql-libs.x86_64 0:9.6.8-1.amzn2.0.1 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    =======================================================================================================================================================================
     Package                                Arch                          Version                                    Repository                                       Size
    =======================================================================================================================================================================
    Installing:
     postgresql                             x86_64                        9.6.8-1.amzn2.0.1                          amzn2extra-postgresql9.6                        1.3 M
    Installing for dependencies:
     postgresql-libs                        x86_64                        9.6.8-1.amzn2.0.1                          amzn2extra-postgresql9.6                        253 k
    
    Transaction Summary
    =======================================================================================================================================================================
    Install  1 Package (+1 Dependent package)
    
    Total download size: 1.6 M
    Installed size: 5.3 M
    Is this ok [y/d/N]: y
    Downloading packages:
    (1/2): postgresql-libs-9.6.8-1.amzn2.0.1.x86_64.rpm                                                                                             | 253 kB  00:00:00     
    (2/2): postgresql-9.6.8-1.amzn2.0.1.x86_64.rpm                                                                                                  | 1.3 MB  00:00:00     
    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Total                                                                                                                                  7.2 MB/s | 1.6 MB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : postgresql-libs-9.6.8-1.amzn2.0.1.x86_64                                                                                                            1/2 
      Installing : postgresql-9.6.8-1.amzn2.0.1.x86_64                                                                                                                 2/2 
      Verifying  : postgresql-libs-9.6.8-1.amzn2.0.1.x86_64                                                                                                            1/2 
      Verifying  : postgresql-9.6.8-1.amzn2.0.1.x86_64                                                                                                                 2/2 
    
    Installed:
      postgresql.x86_64 0:9.6.8-1.amzn2.0.1                                                                                                                                
    
    Dependency Installed:
      postgresql-libs.x86_64 0:9.6.8-1.amzn2.0.1                                                                                                                           
    
    Complete!
    
  7. It will output the summary after installation:
  8.   0  ansible2                 available    [ =2.4.2  =2.4.6 ]
      1  emacs                    available    [ =25.3 ]
      2  httpd_modules            available    [ =1.0 ]
      3  memcached1.5             available    [ =1.5.1 ]
      4  nginx1.12                available    [ =1.12.2 ]
      5  postgresql9.6=latest     enabled      [ =9.6.6  =9.6.8 ]
      6  postgresql10             available    [ =10 ]
      8  redis4.0                 available    [ =4.0.5  =4.0.10 ]
      9  R3.4                     available    [ =3.4.3 ]
     10  rust1                    available    [ =1.22.1  =1.26.0  =1.26.1  =1.27.2 ]
     11  vim                      available    [ =8.0 ]
     12  golang1.9                available    [ =1.9.2 ]
     13  ruby2.4                  available    [ =2.4.2  =2.4.4 ]
     14  nano                     available    [ =2.9.1 ]
     15  php7.2                   available    [ =7.2.0  =7.2.4  =7.2.5  =7.2.8 ]
     16  lamp-mariadb10.2-php7.2  available    [ =10.2.10_7.2.0  =10.2.10_7.2.4  =10.2.10_7.2.5  =10.2.10_7.2.8 ]
     17  libreoffice              available    [ =5.0.6.2_15  =5.3.6.1 ]
     18  gimp                     available    [ =2.8.22 ]
     19  docker=latest            enabled      [ =17.12.1  =18.03.1  =18.06.1 ]
     20  mate-desktop1.x          available    [ =1.19.0  =1.20.0 ]
     21  GraphicsMagick1.3        available    [ =1.3.29 ]
     22  tomcat8.5                available    [ =8.5.31  =8.5.32 ]
     23  epel=latest              enabled      [ =7.11 ]
    
  9. Install the postgresql service package
  10. # sudo yum update
    # sudo yum install postgresql-server.x86_64
    
    # sudo systemctl list-unit-files | grep postgresql
    postgresql.service                            disabled
    postgresql@.service                           disabled
    
    # sudo systemctl enable postgresql.service
    
  11. Inital postgresql database, Create postgres data dir.
  12. # sudo /usr/bin/postgresql-setup --initdb
    # sudo systemctl start postgresql
    
  13. Now you can login and check the Databases.
  14. # sudo -u postgres -- psql
    postgres=> \l
                                      List of databases
       Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
    -----------+----------+----------+-------------+-------------+-----------------------
     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
    (3 rows)
    
  15. My connection config file: /var/lib/pgsql/data/pg_hba.conf
  16. # PostgreSQL Client Authentication Configuration File
    # ===================================================
    #
    # TYPE  DATABASE        USER            ADDRESS                 METHOD
    
    # "local" is for Unix domain socket connections only
    local   all             all                                     md5
    # IPv4 local connections:
    host    all             all             127.0.0.1/32            md5
    # IPv6 local connections:
    host    all             all             ::1/128                 md5
    
It's easy, clean and safer for me.

4 comments:

  1. Thanks you! this is helpful!

    ReplyDelete
  2. I have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favorites blog site list and will be checking back soon. Please check out my site as well and let me know what you think. ein for amazon

    ReplyDelete
  3. great one. simple and too easy

    ReplyDelete