[how to] Creating a PostgreSQL SERIAL column using pgAdmin3 |
- Creating a PostgreSQL SERIAL column using pgAdmin3
- How do you correct a corrupted index in Oracle?
- In SQL Server 2008R2 can I force a View to use objects within the user's default schema instead of the schema in which the View exists?
- One to at most one relation or multiple null columns?
- Table partionning problem
- After moving database (backup, restore), I have to re-add user
- MySQL stored routine performance while using PREPARE
- Shrinking log files with SMO
- How best to maintain SQL log file sizes
- DB2 db2fm proccess
- Msg 21, Level 21, State 1, Line 1 Warning: Fatal error 9001
- How to clean up duplicate objects in SYS/SYSTEM
- MySQL - SQL statement to test minimum length of the word 'ft_min_word_len'
- how can i modify this trigger with loops and concat
- "Rewinding" a Postgresql database
- Is there better way to 'touch' a row than performing a dummy update?
- SQL - Grouping results by custom 24 hour period [closed]
- Is it better to use multiple one-to-many relationships, or polymorphic?
- Live backup without lock
- GROUP BY with OR/AND clause?
- T-SQL Issues With Defining 'AS'
- Updating a table with more than 850 million rows of data
- How to allow a user to create databases only with a certain prefix?
- What could cause the wrong ID to be inserted?
- Transactions, references and how to enforce double entry bookkeeping? (PG)
- Optimization of a select statement
- Rent weekly cost database design
- How to add 'root' MySQL user back on MAMP?
- Referencing database programmatically via T-SQL
Creating a PostgreSQL SERIAL column using pgAdmin3 Posted: 24 Apr 2013 07:05 PM PDT When I use pgAdmin3 to create a column of type Should we keep this type defined by pgAdmin? Manually create the table with SQL defining pgAdmin SQL Pane |
How do you correct a corrupted index in Oracle? Posted: 24 Apr 2013 06:28 PM PDT I have this ORA error in our logs: Caused by: java.sql.BatchUpdateException: ORA-01578: ORACLE data block corrupted (file # 8, block # 22921) ORA-01110: data file 8: '/data/app/oracle/oradata/MYSRVR/datafile/o1_mf_mysrvr_88m82mdj.dbf' I tried running this in sqlplus: select segment_name,segment_type,tablespace_name, owner from sys.dba_extents where file_id=8 and 22921 between block_id and block_id + blocks -1; output is: Now I am stuck on which index is that actual segment name. (I think :/ ) I tried doing this to rebuild that index: SQL> alter index PK_ZXCATSET_CATID rebuild tablespace MYSRVR_IDX_TB;
Even though if I do "select index_name from dba_indexes", that index name shows up. What am I doing wrong? This is a 10.2 Oracle server. Thanks in advance! EDIT If I do MYSRVR.PK_ZXCATSET_CATID the alter completes... but I still don't think my problem is fixed! |
Posted: 24 Apr 2013 05:30 PM PDT A bit of background. I have a base application and most clients use it as standard. However some clients have small code and database customisations. Each of these clients has their own branch and maintenance can be tricky. I want to consolidate all these into a single database structure (not a single database - we aren't doing multi-tenancy) to enable upgrades to be applied in a much more uniform fashion. I'm still at the proof of concept stage, but the route I was going down would be to have the standard objects stay in the schema they currently exist in (mostly dbo) and have the custom objects reside in a schema for each client. For example, I could have dbo.users and client1.users which has some additional columns. If I set the default schema for the client to be "client1" then the following query will return data from the client1 schema or the dbo schema depending on which login is connected. This is absolutely perfect for what I'm trying to achieve. The problem I'm running into is with Views. I have many views which are in the dbo schema and refer to the Users table. No matter which user I connect to the database as, these views always select from dbo.users. So I'm guessing the question I have is: Can I prefix the tables in the view with some variable like "DEFAULT"? e.g. If this isn't possible and I'm totally barking up the wrong tree, do you have any suggestions as to how I can achieve what I'm setting out to do? Many thanks. |
One to at most one relation or multiple null columns? Posted: 24 Apr 2013 04:57 PM PDT I have a table with many attributes that can be grouped in logical groups, and thus the idea of put this attributes in separate tables seems attractive. The logical groups doesn't represent entities themselves. The entity is requested most for reading than for write. Then a large table looks appropriate. Also, this way the joins are avoided in queries. The part I don't like of this approach is the large number of nullable fields resulting. What solution is better? |
Posted: 24 Apr 2013 04:55 PM PDT I need your help for a partionning problem. We are using a "log_event" table which log a lot of events sent by our players (subscription, connection, play, share, etc...). We insert 5,000 row / s in this table. This table is quite big (more than 1 billion lines) and the structure is : In order to increase performance, we would like to partition this table, but :
Do you have any ideas on how to increase performance without cutting the possibility of quick SELECT ? Thanks ! François |
After moving database (backup, restore), I have to re-add user Posted: 24 Apr 2013 04:10 PM PDT I occasionally move a database (SQL Express 2012) from a development machine to a server, or vice versa, using database backup and restore in SQL Server Management Studio. Whenever I do this, the applications on the target machine cannot access the database until I delete the user they use, "george", from the database users (Database, Security, Users in SQL Server Management Studio), and re-add it as owner under Security, Logins, george/properties, user mapping. Is there a better way to do this? It seems a little convoluted. |
MySQL stored routine performance while using PREPARE Posted: 24 Apr 2013 07:11 PM PDT Instead of maintaining stored routines for each database in my current environment i have decided to create separate database just for stored routines storage. Mainly i am using them for reporting. All databases have same schema structure. Stored routine body: Now i faced with performance problem. While executing stored routine from each database execution time is less then 1 sec. With prepared statement 5-6 sec. Could someone please advice if there is space for any improvements. |
Posted: 24 Apr 2013 02:09 PM PDT I know I can use the following t-SQL to shrink a log file: How do I do the same with SMO? I tried: But here, I found that the TruncateLog() method does not work with anything higher than SQL 2005. That link recommended using: However, switching to Simple Recovery Mode is going to break my log chain and I don't want to do that. Shrinking the log file doesn't break my log chain so I'm looking for an equivalent SMO method to do that. Does such a method exist? |
How best to maintain SQL log file sizes Posted: 24 Apr 2013 04:07 PM PDT I'm somewhat of a new DBA and I'm managing a SQL Server 2012 instance that has a fair amount of activity. I'm running in Full Recovery mode because we need point in time recovery. Right now, I'm taking a full backup of the databases and logs every day at 5am. Some of the log files have ballooned up to 300gb and even after taking a backup they don't reduce in size. I can get them to reduce in size by running something similar to: When I check the LSNs of the backup files I see something like: I don't believe I'm breaking my log chain by shrinking the log files. Reading up on this, I do believe I'm hurting my performance because those shrunk log files have to re-grow themselves. Questions:
|
Posted: 24 Apr 2013 03:15 PM PDT Server is been up for 365 days, however i got some weird repeated procceses. Are these normal? ps -fea | grep db2fm db2inst1 643284 229516 29 May 25 - 212564:06 /home/db2inst1/sqllib/bin/db2fm -i db2inst1 -m /home/db2inst1/sqllib/lib/libdb2gcf.a -S db2inst1 671770 229516 56 May 14 - 227447:02 /home/db2inst1/sqllib/bin/db2fm -i db2inst1 -m /home/db2inst1/sqllib/lib/libdb2gcf.a -S db2inst1 757794 1237058 0 Apr 19 pts/7 0:00 /bin/sh /home/db2inst1/sqllib/bin/db2cc db2inst1 774232 229516 30 Sep 25 - 94218:54 /home/db2inst1/sqllib/bin/db2fm -i db2inst1 -m /home/db2inst1/sqllib/lib/libdb2gcf.a -S db2inst1 962750 229516 30 Jul 18 - 145256:01 /home/db2inst1/sqllib/bin/db2fm -i db2inst1 -m /home/db2inst1/sqllib/lib/libdb2gcf.a -S db2inst1 999450 229516 29 Aug 17 - 117710:27 /home/db2inst1/sqllib/bin/db2fm -i db2inst1 -m /home/db2inst1/sqllib/lib/libdb2gcf.a -S db2inst1 1179898 229516 58 Nov 02 - 75788:49 /home/db2inst1/sqllib/bin/db2fm -i db2inst1 -m /home/db2inst1/sqllib/lib/libdb2gcf.a -S ps -fea | grep db2agent db2inst1 409770 680100 0 Apr 19 - 0:00 db2agent (DATABASEA) 0 db2inst1 450750 778412 0 Apr 18 - 0:03 db2agent (idle) 0 db2inst1 618688 680100 0 Apr 19 - 0:00 db2agent (idle) 0 db2inst1 651440 680100 0 Nov 17 - 0:20 db2agent (DATABASEA) 0 db2inst1 655508 491676 0 Apr 19 - 0:04 db2agent (idle) 0 db2inst1 684038 680100 0 Mar 23 - 0:03 db2agent (DATABASEA) 0 db2inst1 790706 491676 0 Apr 19 - 0:00 db2agent (idle) 0 db2inst1 880672 680100 0 Apr 19 - 0:00 db2agent (DATABASEA) 0 db2inst1 913438 778412 0 Nov 16 - 0:20 db2agent (idle) 0 db2inst1 946182 491676 0 Apr 19 - 0:00 db2agent (DATABASEA) 0 db2inst1 991312 778412 0 Apr 17 - 0:16 db2agent (idle) 0 db2inst1 1077466 491676 0 Apr 19 - 0:00 db2agent (DATABASEA) 0 db2inst1 1134726 680100 0 Apr 19 - 0:00 db2agent (DATABASEA) 0 db2inst1 1142964 491676 0 Apr 19 - 0:00 db2agent (idle) 0 db2inst1 1233112 491676 0 Apr 19 - 0:00 db2agent (idle) 0 db2inst1 1261748 778412 0 Jun 15 - 0:18 db2agent (idle) 0 db2inst1 1384678 778412 0 Mar 23 - 0:27 db2agent (idle) 0 db2inst1 1404936 680100 0 Apr 19 - 0:00 db2agent (DATABASEA) 0 db2inst1 1421368 778412 0 Mar 22 - 0:04 db2agent (idle) 0 db2inst1 1445936 491676 0 Apr 19 - 0:00 db2agent (DATABASEA) 0 db2inst1 1482864 491676 0 Jun 16 - 0:31 db2agent (idle) 0 db2inst1 1503440 778412 0 Jun 15 - 0:56 db2agent (idle) 0 db2inst1 1519842 778412 0 Mar 23 - 0:00 db2agent (DATABASEA) 0 db2inst1 1531946 680100 0 Apr 19 - 0:00 db2agent (idle) 0 db2inst1 1572884 680100 0 Apr 19 - 0:00 db2agent (idle) 0 Other info oslevel -g Fileset Actual Level Maintenance Level ----------------------------------------------------------------------------- bos.rte 5.3.0.40 5.3.0.0 db2fm -s -S Gcf module 'fault monitor' is NOT operable Gcf module '/home/db2inst1/sqllib/lib/libdb2gcf.a' state is AVAILABLE uptime 02:14PM up 365 days, 12:51, 6 users, load average: 6.69, 6.89, 6.97 db2level DB21085I Instance "db2inst1" uses "64" bits and DB2 code release "SQL08020" with level identifier "03010106". Informational tokens are "DB2 v8.1.1.64", "s040812", "U498350", and FixPak "7" |
Msg 21, Level 21, State 1, Line 1 Warning: Fatal error 9001 Posted: 24 Apr 2013 02:37 PM PDT We recently moved to a SQL Server that's on a VPS and every now and then we get a 9001 error when trying to do an update. Rebooting the server fixes the problem. I changed the maximum server memory (in MB) to 2000 because it's a 4GB VPS. But I just don't know what's causing the error. |
How to clean up duplicate objects in SYS/SYSTEM Posted: 24 Apr 2013 11:37 AM PDT I have a sql query like below to check duplicate objects in SYS/SYSTEM. I have a list of large duplicated objects. My question / problem is : how to get rid of the objects? What is the best way to approach this? |
MySQL - SQL statement to test minimum length of the word 'ft_min_word_len' Posted: 24 Apr 2013 11:53 AM PDT I'm trying to understand FULLTEXT indexes. Is there some SQL query to test 'ft_min_word_len' variable? I've tried to match four characters only in the example below but it doesn't work. Why the third row is returned if there is no match for '(database|data)' |
how can i modify this trigger with loops and concat Posted: 24 Apr 2013 12:37 PM PDT i have this trigger below which inserts new values in the an emplog table,i want to make my trigger to insert in the description column the event that took place for example if i changed the last_name i want it to appear old.lastname was changed to new.last_name,if its the first-name or gender or dob or marital or ssn that were updated it should do the same,im a newbie how can i achieve this lets say i want to use concat function and loops?? |
"Rewinding" a Postgresql database Posted: 24 Apr 2013 02:02 PM PDT I have heard that Postgresql uses an append-only format for it's databases, and if this is true I should be able to 'rewind' the database to a previous point in time by removing the commits that came after it. Anyone know how I can do this? Thanks |
Is there better way to 'touch' a row than performing a dummy update? Posted: 24 Apr 2013 02:06 PM PDT I use the I'm curious whether there is another way of bumping the |
SQL - Grouping results by custom 24 hour period [closed] Posted: 24 Apr 2013 12:04 PM PDT I need to create an Oracle 11g SQL report showing daily productivity: how many units were shipped during a 24 hour period. Each period starts at 6am and finishes at 5:59am the next day. How could I group the results in such a way as to display this 24 hour period? I've tried grouping by day, but, a day is 00:00 - 23:59 and so the results are inaccurate. The results will cover the past 2 months. Many thanks. |
Is it better to use multiple one-to-many relationships, or polymorphic? Posted: 24 Apr 2013 12:48 PM PDT I've got the following tables:
Both Ads and Websites have many Clicks (i.e. both models have a one-to-many relation with Clicks). In such cases, is it better to use multiple one-to-many relationships, or would a Clickable polymorphic setup be better? |
Posted: 24 Apr 2013 02:37 PM PDT In our company we have a lot of MySQL databases. Some of these are critical and we want to take a back-up of all databases. These databases can't be locked because the application can change these database at every moment. I want to write a script that makes a dump of the database an store it somewhere on a backupdisk. What is the best way to achieve this without locking databases and get a consistent dump off all databases from a remote server. Thanks |
Posted: 24 Apr 2013 01:29 PM PDT Lets say my database looks like this: Table: messages Then in my selection from the table, I want to GROUP BY the following:
Anyone have any ideas how to do that? EDIT: As it seems that i did make some people misunderstanding this. I will now explain better. As I say the ways that I would like to GROUP BY, then when saying They should not be grouped, as Im very sorry for the misunderstanding, hope that someone here are still willing to help me out. |
T-SQL Issues With Defining 'AS' Posted: 24 Apr 2013 04:15 PM PDT I am creating a fully dynamic application but have ran into a bit of a hiccup. There are multiple 'undefined' fields that can be defined by the users. The only problem is redisplaying them. Currently they are showing as [UDF_0] to [UDF_7], i.e. : Would obviously display as: What I would like to be able to do is display them something to this effect, but I can't for the life of me figure it out. Desired display would be : |
Updating a table with more than 850 million rows of data Posted: 24 Apr 2013 08:44 PM PDT I have been tasked with writing an update query to update a table with more than 850 million rows of data. Here are the table structures: Source Tables :
Here is the The relationship between these tables are as follows:
The update requirement is as follows:
The challenge is to do this update on live production, with minimum locking. Here is the query I have put together. It takes about 30 seconds when I set the limit of iterations to 10, by hardcoding the value of All inputs are welcome. Thanks, Raj |
How to allow a user to create databases only with a certain prefix? Posted: 24 Apr 2013 06:08 PM PDT We're having a multi-user Linux server. I'd like to give each user the ability to create and manage databases at will, but to keep things sane, force them that each database name they create must start with their user name as prefix. For example, user |
What could cause the wrong ID to be inserted? Posted: 24 Apr 2013 12:12 PM PDT I have a SQL Server 2008 server (build 10.0.5500). Earlier this week I ran this on a table that already had data in it: When the user went to create a new record later on, somehow an ID of 0 was inserted into the ID column, instead of the 1 SQL Server usually puts in if identity(1,1) is configured for the ID. This caused some weird issues, but clearing the data and running the reseed resulted in a 1 being inserted, as expected. I can't duplicate the issue. For reference, here's the general format for our save sp's: Does anyone know what could cause SQL Server to insert a 0 in the ID when it should have been a 1? |
Transactions, references and how to enforce double entry bookkeeping? (PG) Posted: 24 Apr 2013 06:19 PM PDT Double entry bookkeeping is
An account can be "debited" or "credited", and the sum of all credits must be equal to the sum of all debits. How would you implement this in a Postgres database? Specifying the following DDL: Note: the transaction_details table does not specify an explicit debit/credit account, because the system should be able to debit/credit more than one account in a single transaction. This DDL creates the following requirement: After a database transaction commits on the transactions_details table, it must debit and credit the same amount for each Is it possible to implement this in a PostgreSQL database? Without specifying additional tables to store trigger states. |
Optimization of a select statement Posted: 24 Apr 2013 07:04 PM PDT I'm using MySQL and have a table The reg_data is the unix timestamp of the registration date, and the carrier is the type of carriers, the possible values of which could ONLY be 'D', 'A' or 'V'. I need to write a sql statement to select the registered user number of different carriers on each day from 2013/01/01 to 2013/01/31. So the desirable result could be: Can anyone help me with this question? I'm required to give the BEST answer, which means I can add index if necessary, but I need to keep the query efficient. This is what I have right now: Thanks! The question has been moved to here and please find all the updates in the link. |
Rent weekly cost database design Posted: 24 Apr 2013 01:03 PM PDT I have a database which contains a table BUILDING with in each row details about some building, another table BUILDING_UNIT contains rows with details about a single building unit which refers with a foreign key to the belonging BUILDING.ID. The BUILDING_UNIT table also refers to a table CATEGORY which tells whether the BUILDING_UNIT is of category A,B,C,D again with a foreign key pointing to CATEGORY.ID. Now the final cost of renting the building unit depends on its building, category and on the number of days it is rented and specific period of the year. We only rent them weekly so I might as well use weeks only however I'd like it to be as flexible as possible in the future. I cannot convince myself on a table which can represent this situation. Do I have to use a table with coefficients for each day of the year and then a table with coefficients for A,B,C,D and then a table with coefficients for each Building and then somehow calculate a result? Is there some standard and recognized implementation for problems of this type? Thank you EDIT: Notice the solution should abstract from the formula for calculating the cost which might change in the future. However I might be asked to make a specific week of the year, for building unit X inside building Y to cost 300$ while the week after 600$. Generally building units inside the same building and in the same week cost the same, however that might change in future so I'd like to treat already all specific cases. |
How to add 'root' MySQL user back on MAMP? Posted: 24 Apr 2013 12:03 PM PDT On PhpMyAdmin, I removed 'root' user by mistake. I was also logged in as 'root'. How can I add the user 'root' back, on MAMP? |
Referencing database programmatically via T-SQL Posted: 24 Apr 2013 12:09 PM PDT I am writing a stored procedure that takes a database name as an argument and returns a table of that database's indexes and their fragmentation level. This stored procedure will live in our DBA database (the DB that contains tables the DBAs use for monitoring and optimizing things). The systems in question are all SQL Server 2008 R2 if that makes a difference. I have the basic query worked out, but am stuck on trying to provide the indexes' actual names. To the best of my knowledge, that information is contained in each individual's sys.indexes view. My specific problem is trying to reference that view programmatically from another database's stored procedure. To illustrate, this is the portion of the query at issue: The query works fine when executed from the database identified by @db_id, because it is using the proper sys.indexes view. If I try to call this from the DBA database, however, it all comes up null, as the sys.indexes view is for the wrong database. In more general terms, I need to be able to do something like this: or I have tried switching databases or referencing other databases using combinations of string concatenation and OBJECT_NAME/OBJECT_ID/DB_ID functions and nothing seems to work. I'd appreciate any ideas the community might have, but suspect I will have to retool this stored procedure to reside in each individual database. Thanks in advance for any suggestions. |
You are subscribed to email updates from Recent Questions - Database Administrators Stack Exchange To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
No comments:
Post a Comment