Sponsored Content
Top Forums Programming Need help on Shell script for database maintainace.. Post 302370956 by ashokkumar.p on Friday 13th of November 2009 03:02:16 AM
Old 11-13-2009
Quote:
Originally Posted by TonyLawrence
Is the problem that you are not a postgres user?

su postgresuser commands

does that if you are root.

You could also use "sudo" to allow another user to be the postgres user for these commands; see Using sudo
Hi,

Thanks for the reply, My senario is given below..

Code:
[postgres@sys3 bin]$ ./postgres -D /usr/local/pgsql/data -O -P mydb
LOG:  database system was shut down at 2009-11-11 13:44:47 IST
LOG:  checkpoint record is at 0/AE63A0
LOG:  redo record is at 0/AE63A0; undo record is at 0/0; shutdown TRUE
LOG:  next transaction id: 2254; next oid: 17058
LOG:  database system is ready

POSTGRES backend interactive interface
$Revision: 1.307.2.1 $ $Date: 2003/01/01 21:57:18 $

backend> Reindex Database mydb
NOTICE:  relation 16416 was reindexed
NOTICE:  relation 1255 was reindexed
NOTICE:  relation 16410 was reindexed
NOTICE:  relation 1247 was reindexed
NOTICE:  relation 1249 was reindexed
NOTICE:  relation 1259 was reindexed
NOTICE:  relation 16388 was reindexed
NOTICE:  relation 16390 was reindexed
NOTICE:  relation 16392 was reindexed
NOTICE:  relation 16394 was reindexed
NOTICE:  relation 16396 was reindexed
NOTICE:  relation 16398 was reindexed
NOTICE:  relation 16400 was reindexed
NOTICE:  relation 16402 was reindexed
NOTICE:  relation 16404 was reindexed
NOTICE:  relation 16406 was reindexed
NOTICE:  relation 16412 was reindexed
NOTICE:  relation 16418 was reindexed
NOTICE:  relation 16594 was reindexed
NOTICE:  relation 16596 was reindexed
NOTICE:  relation 16598 was reindexed
NOTICE:  relation 16384 was reindexed
NOTICE:  relation 16386 was reindexed
NOTICE:  relation 16408 was reindexed
backend> LOG:  shutting down
LOG:  database system is shut down

In the above activity there is an interactive command "Reindex Database", I can't call this command in to a shell script. I want to do this activity without my interaction. Please suggest me what to do...

Last edited by vbe; 11-13-2009 at 05:44 AM.. Reason: added code tags...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

can a shell script interact with database?

Hi All, Language like C,Java can interact with database..and can use database information .. can a shall script do this? if yes thn plz guide me..... thankx (7 Replies)
Discussion started by: johnray31
7 Replies

2. Shell Programming and Scripting

Shell Script: want to insert values in database when update script runs

Hi , I am new to linux and also also to shell scripting. I have one shell script which unpacks .tgz file and install software on machine. When this script runs I want to insert id,filename,description(which will be in readme file),log(which will be in log file) and name of unpacked folder... (1 Reply)
Discussion started by: ring
1 Replies

3. Shell Programming and Scripting

what is uses of unix shell script in database projects

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (2 Replies)
Discussion started by: alokjyotibal
2 Replies

4. Shell Programming and Scripting

How do I check using shell-script if an item is available in a database?

Input for the program is a text file consisting of n no. of items. I want search each item in a database and the existing parts should go to FOUND folder and the others should go to NOTFOUND folder. Pls help me in this. Thank u. (1 Reply)
Discussion started by: smarty86
1 Replies

5. Shell Programming and Scripting

Connection to database through shell script

Hi when i am calling the shell script with two parameter like id and date it works fine.But the same shell script is call by java application it gives the error as shown below Thu Jan 8 04:13:22 EST 2009|The Get Segment Process Failed: SP2-0306: Invalid option. Usage: CONN where <logon>... (1 Reply)
Discussion started by: ravi214u
1 Replies

6. Shell Programming and Scripting

get result from database into shell script

hi, I have a script that will logon to a database siebel and do the select query and then get the result in command prompt of unix.Below the script. #!/bin/ksh . $HOME/conf/systemProperties/EnvSetup.properties #set -x while read i do echo $i connect1=`sqlplus -silent... (1 Reply)
Discussion started by: ali560045
1 Replies

7. Shell Programming and Scripting

Connecting to oracle database from shell script

Hi all, I am satyakiran , i am new to the forum. i never done shell scripts for connecting to the data base (oracle) and fetching the data from the database( thru sql select statements ) i want to know 1. how to connect to the data base(oracle) using shell script 2. how to retrieve data... (8 Replies)
Discussion started by: satyakiran
8 Replies

8. Shell Programming and Scripting

Switch from one database to other using shell script

Hi all, This is my first ever post to any forum so, dont let this go in vain...........:) Here is the scenario........ I have logged into the unix where oracle_sid is initialized for some X database in the .profile. I have a unix script where some sql query which fetches data from X... (3 Replies)
Discussion started by: sachinkl
3 Replies

9. Shell Programming and Scripting

Shell Script to connect to the oracle database

Hi Unix Gurus, I have a requirement to write a script, Oracle DB gets referesh every 6hrs, hence we need write a script to connect to the database , if it connects it should generate a file to proceed the next job application or when an error when connectiong to DB it should not generate any... (8 Replies)
Discussion started by: bshivali
8 Replies

10. Shell Programming and Scripting

How to connect to Oracle database using shell script?

Hi All, I am newbie to unix shell scripting. I want to connect to oracle database using shell script. I know how to connect DB using user name and password but my question is if my password is having '@' sign then how to connect. I have tried like below, cnt=`sqlplus -s /nolog << EOFSQL ... (3 Replies)
Discussion started by: pmotewar
3 Replies
REINDEX(7)							   SQL Commands 							REINDEX(7)

NAME
REINDEX - rebuild indexes SYNOPSIS
REINDEX { INDEX | TABLE | DATABASE | SYSTEM } name [ FORCE ] DESCRIPTION
REINDEX rebuilds an index using the data stored in the index's table, replacing the old copy of the index. There are several scenarios in which to use REINDEX: o An index has become corrupted, and no longer contains valid data. Although in theory this should never happen, in practice indexes can become corrupted due to software bugs or hardware failures. REINDEX provides a recovery method. o An index has become ``bloated'', that it is contains many empty or nearly-empty pages. This can occur with B-tree indexes in PostgreSQL under certain uncommon access patterns. REINDEX provides a way to reduce the space consumption of the index by writing a new version of the index without the dead pages. See in the documentation for more information. o You have altered a storage parameter (such as fillfactor) for an index, and wish to ensure that the change has taken full effect. o An index build with the CONCURRENTLY option failed, leaving an ``invalid'' index. Such indexes are useless but it can be convenient to use REINDEX to rebuild them. Note that REINDEX will not perform a concurrent build. To build the index without interfering with produc- tion you should drop the index and reissue the CREATE INDEX CONCURRENTLY command. PARAMETERS
INDEX Recreate the specified index. TABLE Recreate all indexes of the specified table. If the table has a secondary ``TOAST'' table, that is reindexed as well. DATABASE Recreate all indexes within the current database. Indexes on shared system catalogs are skipped except in stand-alone mode (see below). This form of REINDEX cannot be executed inside a transaction block. SYSTEM Recreate all indexes on system catalogs within the current database. Indexes on user tables are not processed. Also, indexes on shared system catalogs are skipped except in stand-alone mode (see below). This form of REINDEX cannot be executed inside a trans- action block. name The name of the specific index, table, or database to be reindexed. Index and table names can be schema-qualified. Presently, REIN- DEX DATABASE and REINDEX SYSTEM can only reindex the current database, so their parameter must match the current database's name. FORCE This is an obsolete option; it is ignored if specified. NOTES
If you suspect corruption of an index on a user table, you can simply rebuild that index, or all indexes on the table, using REINDEX INDEX or REINDEX TABLE. Things are more difficult if you need to recover from corruption of an index on a system table. In this case it's important for the system to not have used any of the suspect indexes itself. (Indeed, in this sort of scenario you might find that server processes are crashing immediately at start-up, due to reliance on the corrupted indexes.) To recover safely, the server must be started with the -P option, which prevents it from using indexes for system catalog lookups. One way to do this is to shut down the server and start a single-user PostgreSQL server with the -P option included on its command line. Then, REINDEX DATABASE, REINDEX SYSTEM, REINDEX TABLE, or REINDEX INDEX can be issued, depending on how much you want to reconstruct. If in doubt, use REINDEX SYSTEM to select reconstruction of all system indexes in the database. Then quit the single-user server session and restart the regular server. See the postgres(1) reference page for more information about how to interact with the single-user server interface. Alternatively, a regular server session can be started with -P included in its command line options. The method for doing this varies across clients, but in all libpq-based clients, it is possible to set the PGOPTIONS environment variable to -P before starting the client. Note that while this method does not require locking out other clients, it might still be wise to prevent other users from connecting to the damaged database until repairs have been completed. If corruption is suspected in the indexes of any of the shared system catalogs (which are pg_authid, pg_auth_members, pg_database, pg_pltemplate, pg_shdepend, pg_shdescription, and pg_tablespace), then a standalone server must be used to repair it. REINDEX will not process shared catalogs in multiuser mode. For all indexes except the shared system catalogs, REINDEX is crash-safe and transaction-safe. REINDEX is not crash-safe for shared indexes, which is why this case is disallowed during normal operation. If a failure occurs while reindexing one of these catalogs in stand- alone mode, it will not be possible to restart the regular server until the problem is rectified. (The typical symptom of a partially rebuilt shared index is ``index is not a btree'' errors.) REINDEX is similar to a drop and recreate of the index in that the index contents are rebuilt from scratch. However, the locking considera- tions are rather different. REINDEX locks out writes but not reads of the index's parent table. It also takes an exclusive lock on the spe- cific index being processed, which will block reads that attempt to use that index. In contrast, DROP INDEX momentarily takes exclusive lock on the parent table, blocking both writes and reads. The subsequent CREATE INDEX locks out writes but not reads; since the index is not there, no read will attempt to use it, meaning that there will be no blocking but reads might be forced into expensive sequential scans. Reindexing a single index or table requires being the owner of that index or table. Reindexing a database requires being the owner of the database (note that the owner can therefore rebuild indexes of tables owned by other users). Of course, superusers can always reindex any- thing. Prior to PostgreSQL 8.1, REINDEX DATABASE processed only system indexes, not all indexes as one would expect from the name. This has been changed to reduce the surprise factor. The old behavior is available as REINDEX SYSTEM. Prior to PostgreSQL 7.4, REINDEX TABLE did not automatically process TOAST tables, and so those had to be reindexed by separate commands. This is still possible, but redundant. EXAMPLES
Rebuild a single index: REINDEX INDEX my_index; Rebuild all the indexes on the table my_table: REINDEX TABLE my_table; Rebuild all indexes in a particular database, without trusting the system indexes to be valid already: $ export PGOPTIONS="-P" $ psql broken_db broken_db=> REINDEX DATABASE broken_db; broken_db=> q COMPATIBILITY
There is no REINDEX command in the SQL standard. SQL - Language Statements 2010-05-14 REINDEX(7)
All times are GMT -4. The time now is 07:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy