Wednesday, April 17, 2013

Oracle CheatSheet

Oracle Listener Commands

lsnrctl
  • start - Start the Oracle listener
  • stop - Stop the Oracle listener
  • status - Display the current status of the Oracle listener
  • services - Retrieve the listener services information
  • version - Display the oracle listener version information
  • reload - This will reload the oracle listener SID and parameter files. This is equivalent to lsnrctl stop and lsnrctl start.
  • save_config – This will save the current settings to the listener.ora file and also take a backup of the listener.ora file before overwriting it. If there are no changes, it will display the message “No changes to save for LISTENER”
  • trace - Enable the tracing at the listener level. The available options are ‘trace OFF’, ‘trace USER’, ‘trace ADMIN’ or ‘trace SUPPORT’
  • spawn - Spawns a new with the program with the spawn_alias mentioned in the listener.ora file
  • change_password – Set the new password to the oracle listener (or) change the existing listener password.
  • show - Display log files and other relevant listener information.

Help example: lsnrctl help show

Starting Up and Shutting Down Database

Start SQL*Plus without connecting to the database:
  • SQLPLUS /NOLOG
Connect to Oracle as SYSDBA:
  • CONNECT username/password AS SYSDBA
Then:
  • STARTUP - Start an Instance
  • SHUTDOWN - Shut Down a Database

Wednesday, January 23, 2013

How to install PostgreSQL 9.1, PostGIS 2.0, pgAdmin 3 and QGIS on Ubuntu 12.10


Here is a simple tutorial on how to install PostgreSQL 9.1, PostGIS 2.0, pgAdmin 3 and QGIS on Ubuntu 12.10.
Open terminal and execute the following code:
Note: you only need to type (or copy/paste) text that comes after $ sign. Text that comes after # is a comment and it will not be executed. Internet connection is required. 

#Install PostgreSQL 9.1
$ sudo apt-get install postgresql-9.1

#Required for PostGIS: Add the ppa (Personal Package Archive) to the current repository
$ sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable

#Required for PostGIS: Update the local package index
$ sudo apt-get update

#Install PostGIS
$ sudo apt-get install postgis

#Install pgAdmin 3
$ sudo apt-get install pgadmin3

#Install Quantum GIS (QGIS)
$ sudo apt-get install qgis

OK, now we should have PostgreSQL with PostGIS up and running. Next thing we need to do is to add new SuperUser. To do that, open terminal and execute the following code:

#Create user zoranp
$ sudo -u postgres createuser
Enter name of role to add: zoranp
Shall the new role be a superuser? (y/n) y

#Set password for created user
$ sudo -u postgres psql postgres
postgres=# \password zoranp

Enter new password:
Enter it again:

Note: You can replace zoranp username with your own.

Next step is to create PostGIS template. Execute the following code in terminal:

#Create the template spatial database
$ createdb -E UTF8 -T template0 template_postgis -U zoranp -W -h localhost

#Load PostGIS SQL routines
$ psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis.sql -U zoranp -W -h localhost

$ psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/spatial_ref_sys.sql -U zoranp -W -h localhost

#Enable users to alter spatial tables
$ psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;" -U zoranp -W -h localhost

$ psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;" -U zoranp -W -h localhost

#Garbage-collect and freeze
$ psql -d template_postgis -c "VACUUM FULL;" -U zoranp -W -h localhost

$ psql -d template_postgis -c "VACUUM FREEZE;" -U zoranp -W -h localhost

#Allow non-superusers the ability to create from this template
$ psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';" -U zoranp -W -h localhost

$ psql -d postgres -c "UPDATE pg_database SET datallowconn='false' WHERE datname='template_postgis';" -U zoranp -W -h localhost

Note: You should check if postgis.sql and spatial_ref_sys.sql files are in /usr/share/postgresql/9.1/contrib/postgis-2.0/ directory. If they are not, you need to find correct directory and replace path in the code.



Screencast: