Rabu, 28 Agustus 2019

How do you create a read only user in postgresql


Grant usage/select to a single table

If you only grant CONNECT to a database, the user can connect but has no other privileges. You have to grant USAGE on namespaces (schemas) and SELECT on tables and views individually like so:

GRANT CONNECT ON DATABASE postgres TO user1;
GRANT USAGE ON SCHEMA public TO user1;
GRANT SELECT ON table01 TO user1;


Multiple tables/views


you can grant permissions on all tables/views/etc in the schema using a single command rather than having to type them one by one:

GRANT SELECT ON ALL TABLES IN SCHEMA public TO user1;

This only affects tables that have already been created. More powerfully, you can automatically have default roles assigned to new objects in future:

ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO user1;


Or you can create role before creating a user, like i usually do

-- Create a group
CREATE ROLE read_access_dwh;

-- Grant access to existing tables
GRANT USAGE ON SCHEMA dwh TO read_access_dwh;
GRANT SELECT ON ALL TABLES IN SCHEMA dwh TO read_access_dwh;

-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA dwhp GRANT SELECT ON TABLES TO read_access_dwh;

-- Create a final user with password
CREATE USER report_dwh WITH PASSWORD 'yourpassword';
GRANT CONNECT ON DATABASE postgres TO report_dwh;
GRANT read_access_dwh TO report_dwh;

Postgres Command Line Connection from shell


This article describes how to connect to a PostgreSQL database from the shell using the psql program.
You can use the psql program as a quick and easy way to access your databases directly.


PSQL Commands: Connect to PostgreSQL from shell

To connect to PostgreSQL cli:
  1. login to the server with SSH where the postgres database is located.

  2. At the shell, type the following command. Replace DBNAME with the name of the database, and USERNAME with the database username:

    psql DBNAME USERNAME

  3. At the Password prompt, type the database user's password. When you type the correct password, the psql prompt appears.

  4. After you access a PostgreSQL database, you can run SQL queries and more. Here are some common psql commands:

    • To view help for psql commands, type \?.
    • To view help for SQL commands, type \h.
    • To view information about the current database connection, type \conninfo.
    • To list the database's tables and their respective owners, type \dt.
    • To list all of the tables, views, and sequences in the database, type \z.
    • To exit the psql program, type \q.

Senin, 19 Agustus 2019

How to install SubversionEdge or CollabNet SVN on Centos


For any company in IT Department, versioning is a darn important part of the development process.

Software versioning is important because:
  • It maintains the history of your code and the sequence in which changes were made
  • It maintains the latest copy of your code in case your computer crashes
  • It helps manage code properly when collaborating with other developers
You’ll understand the importance right away, when a developer you’re working with makes and edit that can’t be reverted or when a client accidentally deletes a file.
Trust me that happens.

In this article, I’m going to talk about installing this very software on Centos


Installing SubversionEdge

because we will install CSVN in user mode, for that we must create CSVN user first.

[root@localhost ~]# adduser csvn
[root@localhost ~]# passwd csvn
Changing password for user csvn.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.


Step #1 The Prerequisites

So, we start with the prerequisites. The prerequisite for SubversionEdge is Java. Hence, to begin with, we’ll have to install Java.
Now, if you’re not sure if Java is already installed, you can fire the below command to check the same:

[root@localhost ~]# java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)

If Java is installed the Java version should be displayed. if java is not installed on your system, you can install java in the following url:


Step #2 Installing CollabNet SVN


Download the latest version of Subversion Edge from CollabNet. It should be a tar.gz file.

Then, use the below commands to install the software. Do remember to replace CollabNetSubversionEdge-5.2.4_linux-x86_64.tar.gz with the tar.gz file you’ve downloaded from CollabNet. and put the downloaded file into the folder /home

[root@localhost ~]# cd /home
[root@localhost home]#
[root@localhost home]# gzip -d CollabNetSubversionEdge-5.2.4_linux-x86_64.tar.gz
[root@localhost home]# tar xf CollabNetSubversionEdge-5.2.4_linux-x86_64.tar
[root@localhost home]# cd /home/csvn/bin/
[root@localhost bin]# ./csvn install
Detected RHEL or Fedora:
Installing the CSVN Console daemon..
Setting RUN_AS_USER to: 'root'. Please edit '../data/conf/csvn.conf' if this needs to be adjusted
Setting JAVA_HOME to: ''. Please edit '../data/conf/csvn.conf' if this needs to be adjusted.

[root@localhost bin]# ./csvn-httpd install
Detected RHEL or Fedora:
 Installing the Subversion Edge Apache Server daemon..

[root@localhost bin]# cd /home/
[root@localhost home]# chown csvn:csvn csvn/ -Rf

login as csvn user and edit file csvn.conf

[csvn@localhost ~]$ vi data/conf/csvn.conf

Setting RUN_AS_USER to: csvn

and back to root account again

CollabNet SVN should now be installed. All we need to do, is start their console and start using the application.
To start their console, fire the command

[root@localhost ~]# service csvn start
Starting CSVN Console...
...
CSVN Console started
Waiting for application to initialize (this may take a minute)...............................
CSVN Console is ready at http://localhost:3343/csvn

Once this command runs successfully, you can view CollabNet SVN at work by heading over to http://localhost:3343/csvn
That’s it! Hope you’ve got the service up and running. and you can adjust the server settings to the existing conditions


Good luck managing your repositories!

Install Java on Centos



INSTALL JAVA 


Download the latest JAVA  from  here or use the following command to download JAVA JDK

# wget --no-cookies \
--no-check-certificate \
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
"https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm" \
-O /tmp/jdk-8u201-linux-x64.rpm

once the JAVA package has been downloaded, install it using rpm as follows:

# rpm -Uvh /tmp/jdk-8u201-linux-x64.rpm

CONFIGURE JAVA

configure the newly installed JAVA package using alternatives as in:

# alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_201-amd64/jre/bin/java 20000
# alternatives --install /usr/bin/jar jar /usr/java/jdk1.8.0_201-amd64/bin/jar 20000
# alternatives --install /usr/bin/javac javac /usr/java/jdk1.8.0_201-amd64/bin/javac 20000
# alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.8.0_201-amd64/jre/bin/javaws 20000
# alternatives --set java /usr/java/jdk1.8.0_201-amd64/jre/bin/java
# alternatives --set javaws /usr/java/jdk1.8.0_201-amd64/jre/bin/javaws
# alternatives --set javac /usr/java/jdk1.8.0_201-amd64/bin/javac
# alternatives --set jar /usr/java/jdk1.8.0_201-amd64/bin/jar

check the JAVA version running on your system:

# java -version

Jumat, 16 Agustus 2019

Fix ORA-03113: end-of-file on communication channel


One day my server died suddenly due to a power problem, this caused a problem with my Oracle database,
ORA-03113: end-of-file on communication channel.

[oracle@localhost ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri Aug 16 14:22:01 2019

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 4993982464 bytes
Fixed Size            2261808 bytes
Variable Size         1006636240 bytes
Database Buffers     3976200192 bytes
Redo Buffers            8884224 bytes
Database mounted.
ORA-03113: end-of-file on communication channel
Process ID: 4903
Session ID: 237 Serial number: 26032

After searching for ways to repair the server, I finally found the solution. Here are the steps:

[oracle@localhost ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri Aug 16 14:22:01 2019

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup mount;
ORACLE instance started.

Total System Global Area 4993982464 bytes
Fixed Size            2261808 bytes
Variable Size         1006636240 bytes
Database Buffers     3976200192 bytes
Redo Buffers            8884224 bytes
Database mounted.

SQL> SELECT GROUP# FROM V$LOG;

    GROUP#
----------
     1
     3
     2

SQL> alter database clear unarchived logfile group 1;
Database altered.

SQL> alter database clear unarchived logfile group 2;
Database altered.

SQL> alter database clear unarchived logfile group 3;
Database altered.

SQL> shutdown immediate;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.

SQL> startup
ORACLE instance started.

Total System Global Area 4993982464 bytes
Fixed Size            2261808 bytes
Variable Size         1006636240 bytes
Database Buffers     3976200192 bytes
Redo Buffers            8884224 bytes
Database mounted.
Database opened.
SQL>

If this method still fails, then there is a second method, which is as follows
Now, go into sqlplus without opening the database, just mounting it.

[oracle@localhost ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Fri Aug 16 14:45:09 2019

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

SQL> connect / as sysdba
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.

Total System Global Area 4993982464 bytes
Fixed Size            2261808 bytes
Variable Size         1006636240 bytes
Database Buffers     3976200192 bytes
Redo Buffers            8884224 bytes
Database mounted.
SQL>

Now, you can increase your current db_recovery_file_dest_size, increased to 100G in my case:

SQL> alter system set db_recovery_file_dest_size = 100G scope=both;

System altered.

Now, you can shutdown and startup again and that previous error should be gone. The proper fix is to get rid of the recovery files. You do that using RMAN

[oracle@localhost ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Fri Aug 16 14:49:39 2019

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: DB11G (DBID=432722608, not open)

RMAN> backup archivelog all delete input;

Starting backup at 16-AUG-19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=156 device type=DISK
specification does not match any archived log in the repository
backup cancelled because there are no files to backup
Finished backup at 16-AUG-19

RMAN> exit


Recovery Manager complete.

Wait a long time and your archivelog (that was using up all that space) will be gone. So, you can shutdown/startup your database and be back in business.

[oracle@jktdi009 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri Aug 16 14:52:16 2019

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown immediate;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area 4993982464 bytes
Fixed Size            2261808 bytes
Variable Size         1006636240 bytes
Database Buffers     3976200192 bytes
Redo Buffers            8884224 bytes
Database mounted.
Database opened.
SQL>

Minggu, 11 Agustus 2019

vsftpd configuration of the ftp server in my company


Just to remember the vsftpd configuration of the ftp server in my company

The following configuration is on centos 6

anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
xferlog_file=/var/log/vsftpd.log
log_ftp_protocol=YES
connect_from_port_20=YES
xferlog_std_format=YES
nopriv_user=ftp
pam_service_name=vsftpd
listen=YES
tcp_wrappers=YES
pasv_enable=YES
pasv_max_port=1200
pasv_min_port=1026
port_enable=YES
ascii_upload_enable=YES
ascii_download_enable=YES
ftpd_banner=Welcome to Private FTP Server.
secure_chroot_dir=/home
one_process_model=NO
chroot_local_user=YES
allow_writeable_chroot=YES
guest_enable=NO
use_localtime=YES
#rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
#rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
seccomp_sandbox=NO

This works since 2011 after upgrading from Centos 5

Minggu, 04 Agustus 2019

If there are ORA-01092 and ORA-30012 errors together


Errors like this

ORA-01092: ORACLE instance terminated. Disconnection forced
ORA-30012: undo tablespace 'UNDOTBS01' does not exist or of wrong type

if there are ORA-01092 and ORA-30012 errors together, here's how to resolve them

[oracle@localhost ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.3.0 Production on Mon Aug 5 10:23:32 2019

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

SQL> connect sys as sysdba
Enter password:
Connected to an idle instance.
SQL>

SQL> startup mount
ORACLE instance started.

Total System Global Area 535662592 bytes
Fixed Size 1375792 bytes
Variable Size 331350480 bytes
Database Buffers 197132288 bytes
Redo Buffers 5804032 bytes
Database mounted.

SQL> select * from v$tablespace;

TS# NAME INC BIG FLA ENC
---------- ------------------------------ --- --- --- ---
0 SYSTEM YES NO YES
1 SYSAUX YES NO YES
4 USERS YES NO YES
3 TEMP NO NO YES
6 EXAMPLE YES NO YES
9 RCRMAN YES NO YES
10 USERS_TBS YES NO YES
5 UNDOTBS2 YES NO YES
19 TESTTBS YES NO YES
14 TESTTB YES NO YES

TS# NAME INC BIG FLA ENC
---------- ------------------------------ --- --- --- ---
15 TESTDB YES NO YES

12 rows selected.

SQL> create pfile='/oracle/product/11.2.0/db_1/dbs/initbckorcl.ora' from spfile;

File created.

SQL> shutdown immediate
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.

Edit Pfile UNDO_TABLESPACE PARAMETER

ORCL.undo_tablespace='UNDOTBS01'
orcl.undo_tablespace='UNDOTBS01'
*.undo_tablespace='UNDOTBS02'

Change like this

ORCL.undo_tablespace='UNDOTBS02'
orcl.undo_tablespace='UNDOTBS02'
*.undo_tablespace='UNDOTBS02'

Startup with new pfile

SQL> startup pfile='/oracle/product/11.2.0/db_1/dbs/initbckorcl.ora';
ORACLE instance started.

Total System Global Area 535662592 bytes
Fixed Size 1375792 bytes
Variable Size 331350480 bytes
Database Buffers 197132288 bytes
Redo Buffers 5804032 bytes
Database mounted.
Database opened.
SQL>

SQL> create spfile from pfile;

File created.

SQL> create spfile from pfile='/oracle/product/11.2.0/db_1/dbs/initbckorcl.ora';

File created.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup
ORACLE instance started.

Total System Global Area 535662592 bytes
Fixed Size 1375792 bytes
Variable Size 331350480 bytes
Database Buffers 197132288 bytes
Redo Buffers 5804032 bytes
Database mounted.
Database opened.

SQL> show parameter undo;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS2