Debugging TNSPING problems in Oracle

All you have to do is use the following two lines in your SQLNET.ORA file.
It will be named tnsping.trc.

The trace level hast 3 options [OFF | USER | ADMIN] the default is OFF.


Here’s the official Oracle documentation for the available parameters and their values in SQLNET.ora

Read More

Java keytool – create keystore


1. Create a new keystore:

Open a command prompt in the same directory as Java keytool; alternatively, you may specify the full path of keytool in your command. Pay close attention to the alias you specify in this command as it will be needed later on.

keytool -genkey -alias mydomain -keyalg RSA -keystore KeyStore.jks -keysize 2048

2. Generate a CSR based on the new keystore:

keytool -certreq -alias mydomain -keystore KeyStore.jks -file mydomain.csr

Answer each question when prompted. Use the chart below to guide you through the process:

Field Example
First & Last Name Domain Name for SSL Certificates
Entity Name for Code Signing
Organizational Unit Support (Optional, e.g. a department)
Organization GMO GlobalSign Inc (Entity’s Legal Name)
City / Locality Portsmouth (Full City name)
State / Province New Hampshire (Full State Name)
Country Code US (2 Letter Code)

Confirm or reject the details by typing “Yes” or “No” and pressing Enter

Press Enter to use the same password as the keystore, alternatively specify a separate password and press enter.

You should now have a file called mydomain.csr which can be used to order or reissue a digital certificate from GlobalSign.

3. While the order processes, download the root & intermediate certificates for your order. You can identify the correct root & intermediate certificate based on hash algorithm and product type.

4. Import the root & intermediate certificates into your keystore. Import the root certificate first, followed by the intermediate. Make sure you specify the correct alias of “root” and “intermediate” respectively.

keytool -import -trustcacerts -alias root -file root.crt -keystore KeyStore.jks
keytool -import -trustcacerts -alias intermediate -file intermediate.crt -keystore KeyStore.jks

5. Download & import your new certificate

Download your new certificate; save it as mydomain.crt.

Use the same alias as the private key so it associates them together. The alias here must match the alias of the private key in the first command.

keytool -import -trustcacerts -alias mydomain -file mydomain.crt -keystore KeyStore.jks

The keystore is now complete and can be used for signing code or deploying on a Java based web server depending on the product you ordered.

To load an existing certificate in a keystore, first create a p12 with openssl, then convert that to .jks using keytool

openssl pkcs12 -export -in server.crt -inkey server.key -out server.p12 -name [some-alias] -CAfile ca.crt -caname root
keytool -importkeystore -deststorepass [changeit] -destkeypass [changeit] -destkeystore server.keystore -srckeystore server.p12 -srcstoretype PKCS12 -srcstorepass some-password -alias [some-alias]
Read More

tcpdump commands

Listen on all interfaces


Listen on all interfaces and specific port(s)

tcpdump port 22 or port 1234

Listen on a specific interface

tcpdump -i eth0

Listen and print packets

tcpdump -i eth0 -A port 80
Read More

Oracle: Select a random row from a table

Read More

PostgreSQL: Delete/drop a database

First check the pg_stat_activity view to see what type of activity is currently taking place against your database, including all idle processes.

SELECT * FROM pg_stat_activity WHERE datname='database name';


select pg_terminate_backend(procpid) from pg_stat_activity where datname='YourDatabase';
#for psql 9.2 and above replace procid with pid

DROP DATABASE "YourDatabase";
Read More

PostgreSQL: Backup and restore

1)Backup data with pg_dump

pg_dump -U postgres -F c -b -v -f "/usr/local/backup/" old_db

To list all of the available options of pg_dump , please issue following command.

pg_dump -?
-p, –port=PORT database server port number
-h, –host=HOSTNAME database server host or socket directory
-U, –username=NAME connect as specified database user
-W, –password force password prompt (should happen automatically)
-d, –dbname=NAME connect to database name
-v, –verbose verbose mode
-F, –format=c|t|p output file format (custom, tar, plain text)
-c, –clean clean (drop) schema prior to create
-b, –blobs include large objects in dump
-v, –verbose verbose mode
-f, –file=FILENAME output file name

2) Restore data with pg_restore

pg_restore -U postgres -d old_db -v "/usr/local/backup/"

To list all of the available options of pg_restore , please issue following command.

pg_restore -?
-p, –port=PORT database server port number
-i, –ignore-version proceed even when server version mismatches
-h, –host=HOSTNAME database server host or socket directory
-U, –username=NAME connect as specified database user
-W, –password force password prompt (should happen automatically)
-d, –dbname=NAME connect to database name
-v, –verbose verbose mode

Read More

Unix: Manually set the date from the command line

In case you do not have a time synchronization with NTP, then you can manually set the date with the date command:

date -s "22 FEB 2017 13:13:00"

Otherwise, verify your NTP service and servers in /etc/ntp.conf

Read More

Windows: Find which process is opening a specific port

Use the following command to find out the list of processes (program and PID):

netstat -a -b -o

Then, in order to kill a specific process use the following command:

taskkill /PID <pid>
Read More

Unix: Tar archive a list of files which are saved in a file

You could find the desired list of files by running the find command e.g.

find /path -type f -name "*.log" | grep -v SomeFiles | grep OtherFiles > mylist.txt

Then archive the list using the command below.

tar -cvf allfiles.tar -T mylist.txt
Read More

PostgreSQL: Simple script to output all functions from DB


FUNCS=`$PSQLBIN/psql -d $DB -c "select proname FROM pg_catalog.pg_proc f where proname like 'process%';"`

for FUNC in $FUNCS ; do
        if [[ $FUNC =~ process.* ]] ; then
                echo `$PSQLBIN/psql -d $DB -c "SELECT pg_get_functiondef(f.oid) FROM pg_catalog.pg_proc f INNER JOIN pg_catalog.pg_namespace n ON (f.pronamespace = n.oid) WHERE n.nspname = 'public' and f.proname='$FUNC';"` > /tmp/"$FUNC".sql

Read More