Tuesday, August 20, 2013

[how to] How to use the check_constraints in postgresql?

[how to] How to use the check_constraints in postgresql?


How to use the check_constraints in postgresql?

Posted: 20 Aug 2013 08:28 PM PDT

I need to check the constraints of the table in database, but i dont understand how to check it inside python program?

Is data encrypted by ENCRYPTBYPASSPHRASE() protected by the service master key?

Posted: 20 Aug 2013 06:24 PM PDT

In a recent question, What does the Service Master Key protect?, it was suggested that the service master key protects, among other things, data encrypted by ENCRYPTPASSPHRASE(). Is this true?

What am I doing wrong with pg_hba.conf?

Posted: 20 Aug 2013 07:13 PM PDT

I'm trying to make it so that local connections to the database don't require a login. So I added the line local all all trust to the pg_hba.conf file, but then when I load pgAdmin and try to connect to the server it just says FATAL: could not load pg_hba.conf. What am I doing wrong?

Create two columns from one, based on two different WHERE clauses

Posted: 20 Aug 2013 06:37 PM PDT

SELECT TOP 1000 [Value]                         FROM [OnlineQnres].[dbo].[tmp_DataSets]  WHERE [VariableID] in ('1')  UNION ALL  SELECT TOP 1000 [Value]  FROM [OnlineQnres].[dbo].[tmp_oDataSets]  WHERE [VariableID] in ('4')  

The above query produces 2000 rows; 1000 with Value for VariableID = 1, and 1000 with Value for VariableID = 2. What I want is 1000 rows, with one column (val1) containing the values for VariableID = 1, and the other column (val2) with the values for VariableID = 2.

Queryplan changes depending on filter values

Posted: 20 Aug 2013 08:38 PM PDT

I created a clustered index on a table expecting it to make the queries with ranges perform better, but, different values in the where clause can produce differente query plans, one uses the clustered index and one does not.

My question is: What can I do to make the DBMS use the better query plan? Or better yet, should I change my schema to something better?

Details:

  • I'm using Amazon's RDS (Server version: 5.5.31-log)
  • I executed optimize table on each table (expecting it to "rebuild" the clustered index and reset the statistics), sometimes it does not change anything, sometimes the DBMS will use worse query plans, sometimes makes it faster because it will use the clustered index.
  • explain extended followed by a show warnings did not produce anyting interesting/useful
  • I'm aware of index hinting. I tested it and the query plan used the primary index but I don't know if it always works, also, I'm using django and django's ORM does not support index hinting, so a solution that did not require it would be nice.

queries:

-- DDL  create table api_route (     id int(11) not null auto_increment primary key,     origin_id int(11) not null,     destination_id int(11) not null,     group_id int(11) not null,     foreign key (origin_id) references api_area (id),     foreign key (destination_id) references api_area (id),     foreign key (group_id) references api_group (id)  ) engine=innodb, collate=utf8;  create table api_area (    id int(11) not null auto_increment primary key,    name varchar(50) not null  ) engine=innodb, collate=utf8;  create table api_location (    id int(11) not null auto_increment primary key,    area_id int(11),    foreign key (area_id) references api_area (id)  ) engine=innodb, collate=utf8;  create table api_locationzip (     location_ptr_id int(11) not null,     zip_start int(11) not null,     zip_end int(11) not null,    foreign key locationzip_to_location (location_ptr_id) references api_location (id)  ) engine=innodb, collate=utf8;  create table api_locationkey (    location_ptr_id int(11) not null,    key varchar(10) not null,    foreign key locationkey_to_location (location_ptr_id) references api_location (id)  ) engine=innodb, collate=utf8;    -- query  select * from    api_route,    api_area origin,    api_area destination,    api_location location_origin,    api_location location_destination,    api_locationzip origin_zip,    api_locationzip destination_zip  where    api_route.group_id IN (1,2,3,...) and    -- filter origin by zip code    api_route.origin_id = origin.id and    origin.id = location_origin.area_id and    location_origin.id = origin_zip.location_ptr_id and    origin_zip.zip_start <= <zipcode_origin> and    origin_zip.zip_end >= <zipcode_origin> and    -- filter destination by zip code    api_route.destination_id = destination.id and    destination.id = location_destination.area_id and    location_destination.id = destination_zip.location_ptr_id and    destination_zip.zip_start <= <zipcode_destination> and    destination_zip.zip_end >= <zipcode_destination>  limit 100  

An area has many locations, every location has either a zip or key.

Here is a explain of a slow query (~1.6s):

*************************** 1. row ***************************             id: 1    select_type: SIMPLE          table: destination           type: index  possible_keys: PRIMARY            key: api_area_group_id_599f0627e68b9613_uniq        key_len: 156            ref: NULL           rows: 3794          Extra: Using index  *************************** 2. row ***************************             id: 1    select_type: SIMPLE          table: api_route           type: ref  possible_keys: api_route_0261d0a2,api_route_8de262d6            key: api_route_8de262d6        key_len: 4            ref: master.T6.id           rows: 9          Extra:   *************************** 3. row ***************************             id: 1    select_type: SIMPLE          table: origin           type: eq_ref  possible_keys: PRIMARY            key: PRIMARY        key_len: 4            ref: master.api_route.origin_id           rows: 1          Extra:   *************************** 4. row ***************************             id: 1    select_type: SIMPLE          table: location_origin           type: ref  possible_keys: PRIMARY,api_location_a4563695            key: api_location_a4563695        key_len: 4            ref: master.origin.id           rows: 39          Extra: Using where; Using index  *************************** 5. row ***************************             id: 1    select_type: SIMPLE          table: origin_zip           type: ref  possible_keys: PRIMARY,locationzip_to_location             key: locationzip_to_location         key_len: 4            ref: master.location_origin.id           rows: 1          Extra: Using where; Using index  *************************** 6. row ***************************             id: 1    select_type: SIMPLE          table: location_destination           type: ref  possible_keys: PRIMARY,api_location_a4563695            key: api_location_a4563695        key_len: 4            ref: master.destination.id           rows: 39          Extra: Using index  *************************** 7. row ***************************             id: 1    select_type: SIMPLE          table: destination_zip           type: ref  possible_keys: PRIMARY,locationzip_to_location             key: locationzip_to_location         key_len: 4            ref: master.location_destination.id           rows: 1          Extra: Using where; Using index  7 rows in set (0.00 sec)  

Here is the explain of a fast query (~100ms):

*************************** 1. row ***************************             id: 1    select_type: SIMPLE          table: destination_zip           type: range  possible_keys: PRIMARY,locationzip_to_location             key: PRIMARY        key_len: 4            ref: NULL           rows: 119268          Extra: Using where; Using index  *************************** 2. row ***************************             id: 1    select_type: SIMPLE          table: location_destination           type: eq_ref  possible_keys: PRIMARY,api_location_a4563695            key: PRIMARY        key_len: 4            ref: master.destination_zip.location_ptr_id           rows: 1          Extra:   *************************** 3. row ***************************             id: 1    select_type: SIMPLE          table: api_route           type: ref  possible_keys: api_route_0261d0a2,api_route_8de262d6            key: api_route_8de262d6        key_len: 4            ref: master.location_destination.area_id           rows: 9          Extra:   *************************** 4. row ***************************             id: 1    select_type: SIMPLE          table: origin           type: eq_ref  possible_keys: PRIMARY            key: PRIMARY        key_len: 4            ref: master.api_route.origin_id           rows: 1          Extra:   *************************** 5. row ***************************             id: 1    select_type: SIMPLE          table: location_origin           type: ref  possible_keys: PRIMARY,api_location_a4563695            key: api_location_a4563695        key_len: 4            ref: master.origin.id           rows: 39          Extra: Using where; Using index  *************************** 6. row ***************************             id: 1    select_type: SIMPLE          table: origin_zip           type: ref  possible_keys: PRIMARY,locationzip_to_location             key: locationzip_to_location         key_len: 4            ref: master.location_origin.id           rows: 1          Extra: Using where; Using index  *************************** 7. row ***************************             id: 1    select_type: SIMPLE          table: destination           type: eq_ref  possible_keys: PRIMARY            key: PRIMARY        key_len: 4            ref: master.location_destination.area_id           rows: 1          Extra:   7 rows in set (0.00 sec)  

edit: Added create table and full query

Guaranteeing a FK relationship through multiple tables

Posted: 20 Aug 2013 06:26 PM PDT

I'm using MySQL / InnoDB, and using foreign keys to preserve relationships across tables. In the following scenaro (depicted below), a 'manager' is associated with a 'recordLabel', and an 'artist' is also associated with a 'recordLabel'. When an 'album' is created, it is associated with an 'artist' and a 'manager', but both the artist and the manager need to be associated with the same recordLabel. How can I guarantee that relationship with the current table setup, or do I need to redesign the tables?

enter image description here

How can I look up table relationships in SQL if I don't have physical/logical models?

Posted: 20 Aug 2013 12:39 PM PDT

What is the best way to look up/learn table relationships in a database that I'm not familiar with? I don't have any documentation on that DB avaiable to me.

Thank you

SQL 2012 Availability Group issue

Posted: 20 Aug 2013 01:10 PM PDT

I need some assistance and some bandages for shooting myself in the foot. This is a DEV environment but I need to bring it up.

I am SQL 2012 Enterprise on Windows 2008 R2. Somehow our AG listener group disappeared. I tried to recreated AG listener and it was giving error regarding computer account not having permissions. The genius inside of me decided to delete AG group from Windows Cluster Admin and now I cannot recreate AG group. ( I should've done it via SQL instead of Windows).

I keep on getting the following error :

TITLE: Microsoft SQL Server Management Studio

Creating availability group resulted in an error. (Microsoft.SqlServer.Management.HadrTasks)

ADDITIONAL INFORMATION:

Create failed for Availability Group 'SQLAG_D'. (Microsoft.SqlServer.Smo)

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

The availability group 'SQLAG_D' already exists. This error could be caused by a previous failed CREATE AVAILABILITY GROUP or DROP AVAILABILITY GROUP operation. If the availability group name you specified is correct, try dropping the availability group and then retry CREATE AVAILABILITY GROUP operation.

Failed to create availability group 'SQLAG_D'. The operation encountered SQL Server error 41042 and has been rolled back. Check the SQL Server error log for more details. When the cause of the error has been resolved, retry CREATE AVAILABILITY GROUP command. (Microsoft SQL Server, Error: 41042)

Does anyone have any suggestions?

What does the Service Master Key protect?

Posted: 20 Aug 2013 07:34 PM PDT

I am looking for a complete list of items that the Service Master Key is used to protect in SQL Server 2008.

Recover encrypted Oracle database

Posted: 20 Aug 2013 02:57 PM PDT

A client fired their DBA. He used OWM to add a wallet to their Oracle database and secure a few necessary columns of tables that they need. I can see the walled using:

orapki wallet display -wallet /opt/oracle/home/owm/root  

I do not know the password. The ex-employee will not divulge the password. With root access to the system, is it possible to remove the wallet or change the wallet's password?

NOTE: Not part of this problem, but for reference... Oracle Support told the client they are out of luck. I told them they are out of luck. They want a third (and fourth (and fifth)) opinion.

Help with Oracle Pipelined function

Posted: 20 Aug 2013 02:16 PM PDT

I have a pivot where I have a contract with tank numbers separated by ; and I've been given this example to pivot them down into rows (which works):

SELECT oks_c.contract_number,          oks_l.line_id,         oks_l.tank_numbers, column_value AS TANK_NUMBER     FROM oks_contract_header oks_c   INNER JOIN oks_contract_lines oks_l       ON oks_l.contract_number = oks_c.contract_number AND          oks_l.item_name LIKE '%.55201'      , table(str2tbl(oks_l.tank_numbers,';')) acbb  ORDER BY oks_c.contract_number,            oks_l.line_id,            TANK_NUMBER  

Here's the pipelined function:

CREATE OR REPLACE function DBRAJAH.str2tbl( p_str in varchar2, p_delim in varchar2 default ',' ) return   str2tblType  PIPELINED  as      l_str      long default p_str || p_delim;      l_n        number;  begin      loop          l_n := instr( l_str, p_delim );          exit when (nvl(l_n,0) = 0);          pipe row( ltrim(rtrim(substr(l_str,1,l_n-1))) );          l_str := substr( l_str, l_n+1 );      end loop;      return;  end;  

But I'm trying to understand why it works. Particularly how the pipelined function results are not cross-joined?

I'm familiar with outer apply and table-valued functions in SQL Server, but this seems to be quite different - or is this really an OUTER APPLY?

EF Code First uses nvarchar(max) for all strings. Will this hurt query performance?

Posted: 20 Aug 2013 12:46 PM PDT

I have some databases created using Entity Framework Code First; the apps are working and in general I'm pretty happy with what code first lets me do. I am a programmer first, and a dba second, by necessity. I am reading about DataAttributes to further describe in C# what I want the database to do; and my question is: what penalty will I be eating by having these nvarchar(max) strings in my table (see example below)?

There are several columns in this particular table; in C# they are defined as such:

    [Key]      [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]      public int ID { get; set; }      public string Name { get; set; }      public string Message { get; set; }      public string Source { get; set; }      public DateTime Generated { get; set; }      public DateTime Written { get; set; }  

I expect to query and/or sort based on Name, Source, Generated, and Written. I expect Name and Source to be in the 0-50 character length, occasionally up to 150. I expect this table to start pretty small (<100k rows), but grow significantly over time (>1m rows). Obviously message could be small or large, and will probably not be queried against.

What I want to know, is there a performance hit for my Name and Source columns being defined as nvarchar(max) when I never expect them to be larger than 150 characters?

Advice needed for Querying DateTimeOffset data by end users

Posted: 20 Aug 2013 08:30 PM PDT

We are building an Operational Data Store (ODS). The data is coming from our production databases which are located in the United States and Asia. The data in our production databases store date/time values as local time (no UTC or offsets). When we bring the data into our ODS, we're storing all date/time values as DateTimeOffset values.

When our users query the ODS data, we don't want them to have to think about including the appropriate offset value in their queries involving date/time values. We want them to be able to query the data as if it were simple local time values.

We're masking the offset values on date/time values by having users query views. The views return local time values and strip off the offset values. While this works, any indexes on the underlying datetimeoffset columns are not used because the act of converting the datetimeoffset to datetime in the views causes indexes to not be used.

So, I'm looking for advice on how others, who have dealt with this issue, have dealed with it. We need to be able to utilize indexes while, at the same time, not require users to think about time zones and daylight savings time when querying the data.

We're using SQL Server 2012.

Query to list all tables in a schema

Posted: 20 Aug 2013 02:29 PM PDT

I am using Rational Application Developer to run querys on a database. We are unable to locate anyone who has a list of the tables on the schema and so far the queries we have found to get a list of tables are unsuccessful.

USE <DB>  GO  SELECT *  FROM sys.Tables  GO  

Use breaks but I replaced it with CALL.

GO breaks as well and I cannot locate a function that does the same thing.

Schema Change/Update script for Database deploy

Posted: 20 Aug 2013 12:37 PM PDT

I have a need to change the database schema . I'm planning to write Schema change and update scripts for tracking database changes and updating them. I followed

Versioning Databases – Change Scripts

for a start, I got a gist of what he is getting at however since I haven't worked much on SQL scripts before, a tutorial or something to start with would be good. I did some research on the web and came to know that most people use Automatic comparing tools to generate the script which I don't want to do for obvious reason that I won't learn the anything in the process.

I'm looking for some tutorials/links on How to write Change scripts and Update scripts ? Especially update scripts as I couln't find even a single script/pseudo-code on how to do update schema by comparing SchemaChangeLog table, connecting to the table using scripts...

Thanks in advance!

Which version of Oracle supports Streams

Posted: 20 Aug 2013 01:49 PM PDT

I am using Oracle 10g Express Edition. I want to enable the streams feature in my current edition. However, when I searched on the net I couldn't find any information regarding streams setup on Oracle XE

Can anyone tell me which version of Oracle supports streams? Is it only the Enterprise Edition that supports it? If yes how can I add streams support to my express or standard editions

Handling or preventing conflicts in a multi-user system

Posted: 20 Aug 2013 12:55 PM PDT

I have a web application that is accessed by multiple users from different locations worldwide. Let's say I have an "edit" form for a specific document and two (or more) users are editing the document at the same time. I know that both of the users can edit the document and submit it, but user1 will not see that user2 made changes to the document and might submit an older version of it.

I was thinking about adding some kind of a lock, but then, if user1 only opened the document for edit, but never changed anything (and kept it open) user2 will never be able to edit it. Therefore, I was thinking to add a Timeout for the editor, but then user1 might time out before he finished doing his changes to the document (let's say, went out for launch).

The question is, how would one prevent the document from being edited from one user while the other changes it?

Migration to databases Domain Users do not have access

Posted: 20 Aug 2013 02:10 PM PDT

I migrated databases to new servers, however the applications that were previously used with the databases are failing to load. I have changed the connections and etc. The jobs also seem to be failing. I have a domain account who is the job owner. However, when I try to execute the job under my User name i get the following error:

Executed as user: NT AUTHORITY\SYSTEM. Login failed for user.....[SQLSTATE 28000) (Error 18456).

Is this related to Domain Users not having appropriate read and write access to the database. Also how would I give All domain users permissions to execute stored procedures.

Creating a global temp table in MySQL

Posted: 20 Aug 2013 12:10 PM PDT

I am working on a MySQL stored procedure.

I need to create a temp table and I want to access this temp table whenever I execute this stored procedure.

I know we can't access the temp table in another request in MySQL.

Is there a way to create a temp table like globally, or how can I access the temp table across the multiple requests?

MySQL server crashed.

Posted: 20 Aug 2013 05:10 PM PDT

Help! I managed to crash MySQL last night. I am on a Mac using the native version that came with Mountain Lion. I was upgrading from 5.5 to 5.6. I have followed instructions in this forum to delete the installation, but trying to re-install 5.5 says that there is a newer version and won't install. Trying to install 5.6 fails. I found this error in the console:

4/21/13 10:16:56.000 PM kernel[0]: exec of /Volumes/mysql-5.6.11-osx10.7-x86/mysql-5.6.11  osx10.7-x86.pkg/Contents/Resources/preflight denied since it was quarantined by TextEdit    and created without user consent, qtn-flags was 0x00000006  

Help me please ?? I am stuck and in a world of hurt and despair.

MySQL database drop insanely slow

Posted: 20 Aug 2013 03:10 PM PDT

I just installed MySQL 5.0.45-log Source distribution on my Debian 6.0.6 server.

I installed it under my user home directory like I'm used to doing.

But this time the queries are extremely slow to run.

Running a create table or a database drop takes ages. I can literally watch tv in the meantime.

So I did a profiling of the database drop statement.

mysql> SHOW PROFILES;  +----------+--------------+------------------------------+  | Query_ID | Duration     | Query                        |  +----------+--------------+------------------------------+  |        1 | 369.54719400 | drop database db_madeintouch |   |        2 |   0.00004600 | SELECT DATABASE()            |   +----------+--------------+------------------------------+  2 rows in set (0.00 sec)    mysql> SHOW PROFILE FOR QUERY 1;  +----------------------+-----------+  | Status               | Duration  |  +----------------------+-----------+  | (initialization)     | 0.000001  |   | checking permissions | 369.54705 |   | Opening table        | 0.000103  |   | System lock          | 0.000003  |   | Table lock           | 0.000018  |   | query end            | 0.000004  |   | freeing items        | 0.000004  |   | logging slow query   | 0.000002  |   +----------------------+-----------+  8 rows in set (0.00 sec)  

We can see the time it takes for the checking of permissions is of 369 seconds.

I also did a show status of the InnoDB engine.

mysql> show engine innodb status\G  *************************** 1. row ***************************  Status:   =====================================  130415 23:11:27 INNODB MONITOR OUTPUT  =====================================  Per second averages calculated from the last 9 seconds  ----------  SEMAPHORES  ----------  OS WAIT ARRAY INFO: reservation count 781, signal count 781  Mutex spin waits 0, rounds 8629, OS waits 231  RW-shared spins 379, OS waits 190; RW-excl spins 380, OS waits 342  ------------  TRANSACTIONS  ------------  Trx id counter 0 7599  Purge done for trx's n:o < 0 7430 undo n:o < 0 0  History list length 3  Total number of lock structs in row lock hash table 0  LIST OF TRANSACTIONS FOR EACH SESSION:  ---TRANSACTION 0 0, not started, process no 14133, OS thread id 140617364518656  MySQL thread id 16, query id 1305 localhost stephane checking permissions  drop database db_madeintouch  ---TRANSACTION 0 0, not started, process no 14133, OS thread id 140617364383488  MySQL thread id 13, query id 1307 localhost stephane  show engine innodb status  ---TRANSACTION 0 7597, COMMITTED IN MEMORY, process no 14133, OS thread id 140617364518656 dropping table  COMMITTING , undo log entries 16  MySQL thread id 16, query id 1305 localhost stephane checking permissions  drop database db_madeintouch  --------  FILE I/O  --------  I/O thread 0 state: waiting for i/o request (insert buffer thread)  I/O thread 1 state: waiting for i/o request (log thread)  I/O thread 2 state: waiting for i/o request (read thread)  I/O thread 3 state: waiting for i/o request (write thread)  Pending normal aio reads: 0, aio writes: 0,   ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0  Pending flushes (fsync) log: 1; buffer pool: 0  174 OS file reads, 3781 OS file writes, 2099 OS fsyncs  0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s  -------------------------------------  INSERT BUFFER AND ADAPTIVE HASH INDEX  -------------------------------------  Ibuf: size 1, free list len 0, seg size 2,  0 inserts, 0 merged recs, 0 merges  Hash table size 17393, used cells 122, node heap has 1 buffer(s)  0.00 hash searches/s, 0.00 non-hash searches/s  ---  LOG  ---  Log sequence number 0 7801057  Log flushed up to   0 7798962  Last checkpoint at  0 7798962  1 pending log writes, 0 pending chkp writes  1535 log i/o's done, 0.00 log i/o's/second  ----------------------  BUFFER POOL AND MEMORY  ----------------------  Total memory allocated 22136914; in additional pool allocated 1048576  Buffer pool size   512  Free buffers       2  Database pages     509  Modified db pages  18  Pending reads 0  Pending writes: LRU 0, flush list 0, single page 0  Pages read 183, created 1444, written 6980  0.00 reads/s, 0.00 creates/s, 0.00 writes/s  No buffer pool page gets since the last printout  --------------  ROW OPERATIONS  --------------  0 queries inside InnoDB, 0 queries in queue  1 read views open inside InnoDB  Main thread process no. 14133, id 140617334142720, state: waiting for server activity  Number of rows inserted 0, updated 0, deleted 0, read 0  0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s  ----------------------------  END OF INNODB MONITOR OUTPUT  ============================    1 row in set (0.00 sec)  

And here is my environment.

mysql> SHOW VARIABLES;

+---------------------------------+--------------------------------------------------------------------+ | Variable_name | Value
| +---------------------------------+--------------------------------------------------------------------+ | auto_increment_increment | 1
| | auto_increment_offset | 1
| | automatic_sp_privileges | ON
| | back_log | 50
| | basedir | /home/stephane/programs/mysql-5.0.45/install/ | | binlog_cache_size | 32768
| | bulk_insert_buffer_size | 8388608
| | character_set_client | latin1
| | character_set_connection | latin1
| | character_set_database | latin1
| | character_set_filesystem | binary
| | character_set_results | latin1
| | character_set_server | latin1
| | character_set_system | utf8
| | character_sets_dir | /home/stephane/programs/mysql-5.0.45/install/share/mysql/charsets/ | | collation_connection | latin1_swedish_ci
| | collation_database | latin1_swedish_ci
| | collation_server | latin1_swedish_ci
| | completion_type | 0
| | concurrent_insert | 1
| | connect_timeout | 5
| | datadir | /home/stephane/programs/mysql/install/data/ | | date_format | %Y-%m-%d
| | datetime_format | %Y-%m-%d %H:%i:%s
| | default_week_format | 0
| | delay_key_write | ON
| | delayed_insert_limit | 100
| | delayed_insert_timeout | 300
| | delayed_queue_size | 1000
| | div_precision_increment | 4
| | engine_condition_pushdown | OFF
| | expire_logs_days | 0
| | flush | OFF
| | flush_time | 0
| | ft_boolean_syntax | + -><()~*:""&|
| | ft_max_word_len | 84
| | ft_min_word_len | 4
| | ft_query_expansion_limit | 20
| | ft_stopword_file | (built-in)
| | group_concat_max_len | 1024
| | have_archive | NO
| | have_bdb | NO
| | have_blackhole_engine | NO
| | have_compress | YES
| | have_crypt | YES
| | have_csv | NO
| | have_dynamic_loading | YES
| | have_example_engine | NO
| | have_federated_engine | NO
| | have_geometry | YES
| | have_innodb | YES
| | have_isam | NO
| | have_merge_engine | YES
| | have_ndbcluster | NO
| | have_openssl | NO
| | have_ssl | NO
| | have_query_cache | YES
| | have_raid | NO
| | have_rtree_keys | YES
| | have_symlink | YES
| | hostname | server1
| | init_connect |
| | init_file |
| | init_slave |
| | innodb_additional_mem_pool_size | 1048576
| | innodb_autoextend_increment | 8
| | innodb_buffer_pool_awe_mem_mb | 0
| | innodb_buffer_pool_size | 8388608
| | innodb_checksums | ON
| | innodb_commit_concurrency | 0
| | innodb_concurrency_tickets | 500
| | innodb_data_file_path | ibdata1:10M:autoextend
| | innodb_data_home_dir |
| | innodb_doublewrite | ON
| | innodb_fast_shutdown | 1
| | innodb_file_io_threads | 4
| | innodb_file_per_table | OFF
| | innodb_flush_log_at_trx_commit | 1
| | innodb_flush_method |
| | innodb_force_recovery | 0
| | innodb_lock_wait_timeout | 50
| | innodb_locks_unsafe_for_binlog | OFF
| | innodb_log_arch_dir |
| | innodb_log_archive | OFF
| | innodb_log_buffer_size | 1048576
| | innodb_log_file_size | 5242880
| | innodb_log_files_in_group | 2
| | innodb_log_group_home_dir | ./
| | innodb_max_dirty_pages_pct | 90
| | innodb_max_purge_lag | 0
| | innodb_mirrored_log_groups | 1
| | innodb_open_files | 300
| | innodb_rollback_on_timeout | OFF
| | innodb_support_xa | ON
| | innodb_sync_spin_loops | 20
| | innodb_table_locks | ON
| | innodb_thread_concurrency | 8
| | innodb_thread_sleep_delay | 10000
| | interactive_timeout | 28800
| | join_buffer_size | 131072
| | key_buffer_size | 16384
| | key_cache_age_threshold | 300
| | key_cache_block_size | 1024
| | key_cache_division_limit | 100
| | language | /home/stephane/programs/mysql-5.0.45/install/share/mysql/english/ | | large_files_support | ON
| | large_page_size | 0
| | large_pages | OFF
| | lc_time_names | en_US
| | license | GPL
| | local_infile | ON
| | locked_in_memory | OFF
| | log | ON
| | log_bin | OFF
| | log_bin_trust_function_creators | OFF
| | log_error | /home/stephane/programs/mysql/install/mysql.error.log | | log_queries_not_using_indexes | OFF
| | log_slave_updates | OFF
| | log_slow_queries | ON
| | log_warnings | 1
| | long_query_time | 10
| | low_priority_updates | OFF
| | lower_case_file_system | OFF
| | lower_case_table_names | 0
| | max_allowed_packet | 1047552
| | max_binlog_cache_size | 18446744073709551615
| | max_binlog_size | 1073741824
| | max_connect_errors | 10
| | max_connections | 100
| | max_delayed_threads | 20
| | max_error_count | 64
| | max_heap_table_size | 16777216
| | max_insert_delayed_threads | 20
| | max_join_size | 18446744073709551615
| | max_length_for_sort_data | 1024
| | max_prepared_stmt_count | 16382
| | max_relay_log_size | 0
| | max_seeks_for_key | 18446744073709551615
| | max_sort_length | 1024
| | max_sp_recursion_depth | 0
| | max_tmp_tables | 32
| | max_user_connections | 0
| | max_write_lock_count | 18446744073709551615
| | multi_range_count | 256
| | myisam_data_pointer_size | 6
| | myisam_max_sort_file_size | 9223372036854775807
| | myisam_recover_options | OFF
| | myisam_repair_threads | 1
| | myisam_sort_buffer_size | 8388608
| | myisam_stats_method | nulls_unequal
| | net_buffer_length | 2048
| | net_read_timeout | 30
| | net_retry_count | 10
| | net_write_timeout | 60
| | new | OFF
| | old_passwords | OFF
| | open_files_limit | 1024
| | optimizer_prune_level | 1
| | optimizer_search_depth | 62
| | pid_file | /home/stephane/programs/mysql/install/data/server1.pid | | port | 3306
| | preload_buffer_size | 32768
| | profiling | OFF
| | profiling_history_size | 15
| | protocol_version | 10
| | query_alloc_block_size | 8192
| | query_cache_limit | 1048576
| | query_cache_min_res_unit | 4096
| | query_cache_size | 0
| | query_cache_type | ON
| | query_cache_wlock_invalidate | OFF
| | query_prealloc_size | 8192
| | range_alloc_block_size | 2048
| | read_buffer_size | 258048
| | read_only | OFF
| | read_rnd_buffer_size | 258048
| | relay_log_purge | ON
| | relay_log_space_limit | 0
| | rpl_recovery_rank | 0
| | secure_auth | OFF
| | secure_file_priv |
| | server_id | 1
| | skip_external_locking | ON
| | skip_networking | OFF
| | skip_show_database | OFF
| | slave_compressed_protocol | OFF
| | slave_load_tmpdir | /tmp/
| | slave_net_timeout | 3600
| | slave_skip_errors | OFF
| | slave_transaction_retries | 10
| | slow_launch_time | 2
| | socket | /tmp/mysql.sock
| | sort_buffer_size | 65528
| | sql_big_selects | ON
| | sql_mode |
| | sql_notes | ON
| | sql_warnings | OFF
| | ssl_ca |
| | ssl_capath |
| | ssl_cert |
| | ssl_cipher |
| | ssl_key |
| | storage_engine | MyISAM
| | sync_binlog | 0
| | sync_frm | ON
| | system_time_zone | MSK
| | table_cache | 4
| | table_lock_wait_timeout | 50
| | table_type | MyISAM
| | thread_cache_size | 0
| | thread_stack | 131072
| | time_format | %H:%i:%s
| | time_zone | SYSTEM
| | timed_mutexes | OFF
| | tmp_table_size | 33554432
| | tmpdir | /tmp/
| | transaction_alloc_block_size | 8192
| | transaction_prealloc_size | 4096
| | tx_isolation | REPEATABLE-READ
| | updatable_views_with_limit | YES
| | version | 5.0.45-log
| | version_comment | Source distribution
| | version_compile_machine | x86_64
| | version_compile_os | unknown-linux-gnu
| | wait_timeout | 28800
| +---------------------------------+--------------------------------------------------------------------+ 225 rows in set (43.41 sec)

SQL Server replication conflicts after migration from 2000 to 2008

Posted: 20 Aug 2013 08:10 PM PDT

I got a suggestion over at Stackoverflow to post here....greatful for any and all help.

Please bear with me I think this might take a while to explain. For many years now my company has hosted a solution for a client involving a complex web application with smaller mobile solution consisting of IIS 6 for the web app, SQL Server 2000 on its own server and Visual Studio 2005 Pocket PC app replicating with SQL Server via Merge Replication. This whole time the mobile solution has been very solid and did not require many updates so we have replicated with sscesa20.dll the entire time.

We recently migrated this entire solution as follow:

  • Web Box - New Win Server 2008 R2 running IIS 7.5
  • SQL Server Box - New Win Server 2008 R2 running SQL Server 2008
  • Mobile app - small updates converted to Visual Studio 2008 and Windows for Mobile 5

The new web box received the 64 bit version of SQL Server Compact 3.5 tools and we now call sqlcesa35.dll from the mobile device to perform merge replication.

The basic idea of the entire process is that mobile field users get assigned safety inspections to perform on buildings. When a facility in the system needs an inspection an inspection record is created via the web app in the DB. A status flag is set such that the HOST_NAME() is utilized to make sure only records for a given inspector with this particular status will let them show up on their mobile device. The user can synch multiple times in the field sending their data up to the SQL Server/web app and receive more inspections down or other updates such as look up table data...typical merge replication here and has been working great for years. Once the field user changes the status of the inspection, it will travel from mobile device to SQL Server database and be removed from their iPaq. The inspection has additional work flow on the web app from here on out.

Now on to the problem. We migrated everything publishing the exact same subset of tables with the same joins/filters. Same settings on the publication as far as I can tell are the same. However; when a user gets a new inspection down to the hand held for the very first time, enters data, then synchronizes back to the database every row has a conflict. Since we have default conflict resolution the publisher wins and the data collected in the field it lost. The inspection now looks blank just as it did when it first came down to the mobile device. If the user syncs again with or without changes on the mobile (subscriber) all is well. Any future changes from the mobile device are intact.

It is as if the web/db data is newer then the hand held data. I am 100% sure it is not. I have looked at table triggers, web app logic, etc. We were very careful not to include any application changes to DB/web app/mobile app with respect to data manipulation during this migration.

Here is a summary of the order of operation:

New row created in the database >> Mobile user receives data >> mobile user updates data >> synchronizes - data is lost. Conflicts show up for all data lost.

From here on out any additional mobile changes are captured. Merge replication works in both directions flawlessly.

Thanks for taking the time to read please help. I am stuck after 3 days.

Running a TPC-C Benchmark Without sleep() i.e. key-in + think time

Posted: 20 Aug 2013 11:10 AM PDT

We are running a TPC-C benchmark against a PostgreSQL 9.2 server using JdbcRunner-1.2 implementation. During first few tests we were not getting a smooth (that is, without sudden spikes down to almost 0 from 300 that we got at times) TPS graph even in supposedly steady state. During these tests we had not specified the sleeptimes for transactions (there are different sleep times recommended for different transaction types). So, by default all agents (for example, 100) continuously ran a mix of five transaction types without any sleeps in between. Later, we found out that we could in fact specify the sleep times; and when we did we could see a smoother graph without much variations.

So, the question is, if not specifying the sleep could be the real reason behind the bad results in first few tests?

How to connect to a Database made by Oracle SQL Database?

Posted: 20 Aug 2013 07:10 PM PDT

So I am fairly new at this, so if you could keep that in mind in your answers, it would be much appreciated. I installed Oracle SQL Database on my Windows PC. It came in two zip files. I installed it and the online portion of it works fine. I can login with Username: sys and Password: **. What I am trying to do is connect to this newly created database on another computer through SQL Developer. I have read that in order to do this, you need to change the hostname of the Database from "localhost" to an IP Address. How do I do that and is there anything else I need to do to make this work?

I also found this LINK. Is this something I should do? I do not have a Domain though.

listener.ora

# listener.ora Network Configuration File:    C:\app\hyderz\product\11.2.0\dbhome_2\network\admin\listener.ora  # Generated by Oracle configuration tools.    SID_LIST_LISTENER =  (SID_LIST =   (SID_DESC =     (SID_NAME = CLRExtProc)     (ORACLE_HOME = C:\app\hyderz\product\11.2.0\dbhome_2)     (PROGRAM = extproc)     (ENVS = "EXTPROC_DLLS=ONLY:C:\app\hyderz\product\11.2.0\dbhome_2\bin\oraclr11.dll")   )  )    LISTENER =  (DESCRIPTION_LIST =    (DESCRIPTION =      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1522))      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522))    )  )    ADR_BASE_LISTENER = C:\app\hyderz  

tnsnames.ora

# tnsnames.ora Network Configuration File:   C:\app\hyderz\product\11.2.0\dbhome_2\network\admin\tnsnames.ora  # Generated by Oracle configuration tools.    LISTENER_ORCL =    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522))      ORACLR_CONNECTION_DATA =  (DESCRIPTION =  (ADDRESS_LIST =    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1522))  )  (CONNECT_DATA =    (SID = CLRExtProc)    (PRESENTATION = RO)  )  )    ORCL =  (DESCRIPTION =  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522))  (CONNECT_DATA =    (SERVER = DEDICATED)    (SERVICE_NAME = orcl)  )  )  

Deleting folders after Oracle upgrade

Posted: 20 Aug 2013 01:10 PM PDT

I upgraded from Oracle 10g to Oracle 11g in Windows Server 2003.

New Oracle home : C:\app\oracle\product\11.2.0\db_1

Old Oracle 10g was installed on: C:\oracle\product\10.2.0\

Questions

  • Is the 10g folder is still useful?
  • Could I delete the 10g folder without a problem?

How to optimize a log process in MySQL?

Posted: 20 Aug 2013 04:10 PM PDT

In my project, I have about 100.000 users and can't control their behavior. Now, what I would like to do is log their activity in a certain task. Every activity, is one record which includes columns like user_id and some tag_id's.

The problem I have, is that these tasks in some cases can go up to 1.000.000 per year per user. So if I would store all these activities in one table. that would obviously become very big (=slow).

What is best to do here? Create a single table per user (so I have 100.000 log tables) or put all these activities in one table? And what kind of engine should I use?

One important thing to note: Although i simplified the situation a bit the following doesn't look normal, but users can also change values in these tables (like tag_id's).

Disabling Checking of Schema On Function/Stored Procedure Creation

Posted: 20 Aug 2013 07:32 PM PDT

I'm trying to automate the process that executes changes to the SQL Server 2008 R2 database. The process I put in place drops and recreates my stored procedures and functions, as well as run scripts to change the tables/columns/data. Unfortunately, one of the scripts requires one of the functions to be put in place first. But I can't run all stored proc/function changes first because it relies on columns being added from the tables/columns/data change scripts first.

I was wondering if it was possible to run stored procedures and functions without SQL Server validating the columns used in the definition of the function/SP? I tried looking but couldn't find a condition or command to enable this.

Thanks.

Designing a database for a site that stores content from multiple services?

Posted: 20 Aug 2013 06:10 PM PDT

I'm building a site that implements David Allen's Getting Things Done that pulls in your email, Facebook newsfeed, tweets from those you follow on Twitter, and more services are planned. The problem is that I'm not a DBA, and I'm not sure how to design the database so that as I add features to the site, I won't have to artificially corrupt people's raw data for the purposes of storing it (for example, I want to add the ability to get RSS feeds sometime in the future, but I'm not sure how I'd do that without making a mess).

I've put down my initial ideas using DBDesigner 4, below, you'll find the diagram and the SQL.

A few notes to help clarify clarify things.

  • The Accounts table is for storing authentication tokens and such for facebook, twitter, and such.
  • The messages table is incomplete.
  • The password fields in emailconfiguration and users are encrypted, users with a one-way hash, emailconfiguration with a two-way.
  • I'm using a MySQL database using the InnoDB storage engine on Amazon RDS.
  • Each project may have one context associated with it.
  • Each message may have a project and context, but it's not required.
  • The imap, smtp, and pop3 tables exist to remove duplication within email configuration.
  • queries to this database are generated by Korma, a clojure library.

Can someone please point me in the right direction? I'd also be willing to look at using a NoSQL database if suggested. Thank you for your time and consideration.

site database schema

Here's the SQL create script just in case anyone wants to see it.

CREATE TABLE Pop3 (    domain VARCHAR NOT NULL,    host VARCHAR NULL,    port INTEGER UNSIGNED NULL,    ssl BOOL NULL,    PRIMARY KEY(domain)  )  TYPE=InnoDB;    CREATE TABLE Imap (    domain VARCHAR NOT NULL,    Host VARCHAR NULL,    port INTEGER UNSIGNED NULL,    ssl BOOL NULL,    PRIMARY KEY(domain)  )  TYPE=InnoDB;    CREATE TABLE users (    Username VARCHAR NOT NULL AUTO_INCREMENT,    email VARCHAR NULL,    password_2 VARCHAR NULL,    activation VARCHAR NULL,    is_active BOOL NULL,    PRIMARY KEY(Username)  )  TYPE=InnoDB;    CREATE TABLE smtp (    domain VARCHAR NOT NULL,    host VARCHAR NULL,    port INTEGER UNSIGNED NULL,    ssl BOOL NULL,    PRIMARY KEY(domain)  )  TYPE=InnoDB;    CREATE TABLE projects (    id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,    users_Username VARCHAR NOT NULL,    name VARCHAR NULL,    description TEXT NULL,    context INTEGER UNSIGNED NULL,    PRIMARY KEY(id, users_Username),    INDEX projects_FKIndex1(users_Username),    FOREIGN KEY(users_Username)      REFERENCES users(Username)        ON DELETE NO ACTION        ON UPDATE NO ACTION  )  TYPE=InnoDB;    -- ------------------------------------------------------------  -- This is the table where access info for facebook, twitter, and others is stored.  -- ------------------------------------------------------------    CREATE TABLE Accountsi (    id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,    users_Username VARCHAR NOT NULL,    owner INTEGER UNSIGNED NULL,    service VARCHAR NULL,    username VARCHAR NULL,    send INTEGER UNSIGNED NULL,    receive INTEGER UNSIGNED NULL,    info TEXT NULL,    PRIMARY KEY(id, users_Username),    INDEX Accountsi_FKIndex1(users_Username),    FOREIGN KEY(users_Username)      REFERENCES users(Username)        ON DELETE NO ACTION        ON UPDATE NO ACTION  )  TYPE=InnoDB;    CREATE TABLE EmailConfiguration (    id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,    users_Username VARCHAR NOT NULL,    owner INTEGER UNSIGNED NOT NULL,    address VARCHAR NULL,    psswd VARCHAR BINARY NULL,    domain VARCHAR NULL,    PRIMARY KEY(id, users_Username),    INDEX EmailConfiguration_FKIndex1(users_Username),    FOREIGN KEY(users_Username)      REFERENCES users(Username)        ON DELETE NO ACTION        ON UPDATE NO ACTION  )  TYPE=InnoDB;    CREATE TABLE Messages (    id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,    users_Username VARCHAR NOT NULL,    message_id VARCHAR NULL,    user_id VARCHAR NULL,    account INTEGER UNSIGNED NULL,    service VARCHAR NULL,    project INTEGER UNSIGNED NOT NULL,    context INTEGER UNSIGNED NOT NULL,    PRIMARY KEY(id, users_Username),    INDEX Messages_FKIndex1(users_Username),    FOREIGN KEY(users_Username)      REFERENCES users(Username)        ON DELETE NO ACTION        ON UPDATE NO ACTION  )  TYPE=InnoDB;    CREATE TABLE context (    id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,    projects_id INTEGER UNSIGNED NOT NULL,    projects_users_Username VARCHAR NOT NULL,    users_Username VARCHAR NOT NULL,    name VARCHAR NULL,    description TEXT NULL,    PRIMARY KEY(id, projects_id, projects_users_Username, users_Username),    INDEX context_FKIndex1(projects_id, projects_users_Username),    INDEX context_FKIndex2(users_Username),    FOREIGN KEY(projects_id, projects_users_Username)      REFERENCES projects(id, users_Username)        ON DELETE NO ACTION        ON UPDATE NO ACTION,    FOREIGN KEY(users_Username)      REFERENCES users(Username)        ON DELETE NO ACTION        ON UPDATE NO ACTION  )  TYPE=InnoDB;  

[MS SQL Server] Rename Server

[MS SQL Server] Rename Server


Rename Server

Posted: 20 Aug 2013 04:52 AM PDT

Hello EveryoneI am working with a company that needs, or wants to rename one of the SQL boxes to a name of an existing SQL box. The plan is to remove the original box from the network. Rename the other box to the name of the original server. My question is this: What impact will this have one the current SQL Instance that is on that new box? Will SQL Server Service even start?Has anyone tried this? Or had to perform this task? I do not have a couple servers on hand to test this, or I would.Thanks in advance for all your assistance, suggestions and comments.Andrew SQLDBA

Restoring ReportServer Database

Posted: 22 Apr 2011 12:47 AM PDT

I'm setting up and testing a new SQL Server 2008 R2. I'm testing backup/restore of the ReportServer database using Management Studio.For an attempted restore I have the "Overwrite the existing database (with replace)" and "Leave the database ready to use by rolling back uncommitted transactions" options selected.I get this error message: "Restore failed for server: Exclusive access could not be obtained because the database is in use." I'm attempting to restore from full and differential backups. No transaction log backups.Can someone tell me the proper way to restore the ReportServer database?

Impact of creating a non clustered index

Posted: 20 Aug 2013 12:37 AM PDT

Hi Experts,Please let know the impact of creating a non-clustered index on a table having 10million records and columns included in index are of int datatype.Thanks in Advance

MDF file too large. PRIMARY FILE GROUP FULL error

Posted: 19 Aug 2013 04:10 PM PDT

I run SQL Server 2008 Express R2 on my local machine with Windows 7 Home Premium. I use the db to run a dotnetnuke 7 website. Everything went on fine until I got a "Cannot allocate space to object 'x'....PRIMARY FILE GROUP IS FULL" error message one day. I have cleared the logs from the application but the error persisted. I checked the database and found the mdf file has grown to over 10GB is size while the ldf file was around 175MB. The details of database are as follows:SQL Server 2008 Express R2Recovery Mode: Simplemdf file size: 10.23 GBInitial size: 10.23 GB (it shows the same)Space Remaining: 0.0 GBData File autogrowth settings: by 10MB, Unrestricted Growthldf file size: 173 MBLog File autogrowth settings: by 10% Restricted GrowthAlso when I try to shrink the file from the management studio-tasks it says cannot find such file. However the file is very well there in the path mentioned.Error DetailsFile Error Index #: 0Source: .Net SqlClient Data ProviderClass: 17Number: 1105Procedure: AddEventLogMessage: System.Data.SqlClient.SqlException (0x80131904): Could not allocate space for object 'dbo.EventLog'.'PK_EventLogMaster' in database 'hescom_db' because the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at PetaPoco.Database.Execute(String sql, Object[] args) at DotNetNuke.Data.PetaPoco.PetaPocoHelper.ExecuteNonQuery(String connectionString, CommandType type, String sql, Object[] args) at DotNetNuke.Data.SqlDataProvider.ExecuteNonQuery(String procedureName, Object[] commandParameters) at DotNetNuke.Data.DataProvider.AddLog(String logGUID, String logTypeKey, Int32 logUserID, String logUserName, Int32 logPortalID, String logPortalName, DateTime logCreateDate, String logServerName, String logProperties, Int32 logConfigID) at DotNetNuke.Services.Log.EventLog.DBLoggingProvider.WriteLog(LogQueueItem logQueueItem)I am new to DB management and any help is appreciated. Thank You.

Ideal Log File Size Set up in Sql 2008

Posted: 19 Aug 2013 05:59 AM PDT

I would like to know what will be the ideal setting for Log file set up?I have Data File, Log File and Temp DB on seperate Disk drive.I have set up the Data File Initial Size: 100 GB - Growth - 5 GB as total Daat File Drive has 1 TB Capacity.I am little confused for Log file as We have Replication Subscription will be running on that DB and it will total size of the DB is 300 GB Plus.Replication will run frequently as well as couple batch job running.If I set up Log File: 50 GB - Growth - 1 GB as my total Log file drive is configured - 100 GB.Thanks and appreciate your response!

[Articles] Guidance

[Articles] Guidance


Guidance

Posted: 19 Aug 2013 11:00 PM PDT

When you are looking to help someone improve performance on a system, there isn't a single set of steps you provide. The advice and guidance you provide will vary, depending on the situation.

[SQL 2012] Count and Sum over the some table

[SQL 2012] Count and Sum over the some table


Count and Sum over the some table

Posted: 19 Aug 2013 03:43 AM PDT

Hi allSuppose we have a table DATHIS with the following information:[X1]---------[X2]-[X3]2013-08-10, 1250, 75.02013-08-10, 1251, 82.02013-08-10, 1252, 35.02013-08-10, 1253, 45.02013-08-11, 1250, 75.12013-08-11, 1251, 82.22013-08-11, 1252, 50.32013-08-11, 1253, 50.42013-08-12, 1250, 75.52013-08-12, 1251, 82.62013-08-12, 1252, 45.72013-08-12, 1253, 55.8We need the output like this:[Y1]--------[Y2]--[Y3]-[Y4]2013-08-10, 75.0, 82.0, 02013-08-11, 75.1, 82.2, 22013-08-12, 75.5, 82.6, 1On Y4 column we need to count the number of X2 IN (1252, 1253) >= 50. We did the following SQL command for Y1, Y2 and Y3:SELECT X1 Y1, [1250] Y2, [1251] Y3 FROM(SELECT X1, X2, X3 FROM DATHIS WHERE X1>='2013-08-10') H PIVOT ( SUM(X3) FOR X2 in ([1250], [1251]) ) AS DHORDER BY X1But, now how can we include Y4, for counting of number of rows >= 50.0 for X2 IN (1252, 1253)?Any one have an idea for that, please?Best RegardsPaulo:hehe: :crazy:

Table data in tabular form

Posted: 05 Aug 2013 10:20 PM PDT

CREATE TABLE [dbo].[LeaveEntry]( [LeaveId] [int] IDENTITY(1,1) NOT NULL, [Name] [varchar](50) NOT NULL, [LeaveTypeName] [int] NOT NULL, [StartDate] [datetime] NULL, [EndDate] [datetime] NULL, )INSERT INTO LeaveEntry VALUES (1, 'A','OUT','2013-08-29 00:00:00.000','2013-09-29 00:00:00.000'), (2, 'B','LON','2013-08-29 00:00:00.000','2013-09-29 00:00:00.000'), (3, 'C','OUT','2013-08-29 00:00:00.000','2013-09-29 00:00:00.000'); I want to do a report in ssis where I have to send an email i a tabular form for each weeksomething likeWeek 1<table border="1px"><tr><td></td><td>A</td> <td>B</td> <td>C</td> </tr><td>Monday</td><td>OUT</td><td>LON</td><td></td></tr><tr><td>Tuesday</td><td></td><td></td><td>LON</td></tr><tr><td>Wednesday</td><td>OUt</td><td></td><td>LON</td></tr><tr><td>Thurday</td><td></td><td></td><td></td></tr><tr><td>Friday</td><td></td><td>OUT</td><td></td></tr></table> Week 2<table border="1px"><tr><td></td><td>A</td> <td>B</td> <td>C</td> </tr><td>Monday</td><td>OUT</td><td>LON</td><td></td></tr><tr><td>Tuesday</td><td></td><td></td><td>LON</td></tr><tr><td>Wednesday</td><td>OUt</td><td></td><td>LON</td></tr><tr><td>Thurday</td><td></td><td></td><td></td></tr><tr><td>Friday</td><td></td><td>OUT</td><td></td></tr></table>

Problem with agent service accounts?

Posted: 06 Aug 2013 07:33 AM PDT

Hey guys. Ive never had this problem with SQL2008 /R2. But I cant get the SQL Agent to log in with anything but local system or a local user that has admin rights on the server. Generally, I would make a SQL_svc_agent_user and grant no rights and and using the sql installer it would grant any permissions including log on a service and add NT SERVICE\SQLSERVERAGENT as SA. Now even with all that in place this user cannot log on in 2012. Even if I granted SQL_svc_agent_user SA rights in Management Studio this still does not work. Seems like something changed in 2012? What am i missing here? The service account for SQL runs just fine but not the agent. This is a local account, but the machine is connected to a domain. Its driving me nuts!:hehe:

Create Asymmetric key from executable file

Posted: 19 Aug 2013 07:01 AM PDT

Sorry Admins - Please delete this thread, shouldnt have posted without doing proper research.

[T-SQL] Importing XML file into SQL 2008R2...nearly there

[T-SQL] Importing XML file into SQL 2008R2...nearly there


Importing XML file into SQL 2008R2...nearly there

Posted: 20 Aug 2013 12:29 AM PDT

Hi,Trying to import a file with the structure:<PetrolPrices> [left]<Fuel type="Super Unleaded"> <Average units="p">145.83</Average> </Fuel> <Fuel type="Unleaded"> <Average units="p">137.42</Average> </Fuel> <Fuel type="Premium Diesel"> <Average units="p">151.63</Average> </Fuel> <Fuel type="Diesel"> <Average units="p">141.64</Average> </Fuel> <Fuel type="LPG"> <Average units="p">70.57</Average> </Fuel>[/left]</PetrolPrices>Using:select c3.value('Fuel[1]','Varchar(30)') as [Fuel Type], c3.value('Average[1]','decimal(18,3)') as [Average Units] from( select cast(c1 as xml) from OPENROWSET (BULK 'C:\FuelCosts\UK averages_20130819.xml',SINGLE_BLOB) as T1(c1))as T2(c2)cross apply c2.nodes('/PetrolPrices/Fuel') T3(c3)Which gives me:Fuel Type Average UnitsNULL 145.830NULL 137.420NULL 151.630NULL 141.640NULL 70.570Can someone help me out with what I am doing wrong for the Fuel Type please.many thanksMark

Year to Date Query ... By month?

Posted: 20 Aug 2013 12:44 AM PDT

Hi, I have a table which currently has a month and a number by month representing lets say car sales,Table CarMonth - DateSales - Int I would like to get a Year To Date formula going which i understand how to do for one value for the most recent month Sum(Sales) from Car Where Month >= '2012-04-01' however its getting complicated because i need to show the year to date data by month, so i need to create some sort of loop to go though every month?Example:April 2012 - #=5 YTD=5May 2012 - #=10 YTD=15June 2012 - #=2 YTD=17any help is greatly appreciated

need help and getting unique set

Posted: 19 Aug 2013 06:19 AM PDT

Hi all,I need a help on getting the distinct set.My Data look like this:SET 1SET ID Product Attribute1 A 101 A 11SET 2SET ID Product Attribute2 A 102 A 12SET 3SET ID Product Attribute3 A 103 A 11Since set ID 1 and 3 has the same product and attribute I just need to get distinct set having the same product and attribute. The result set will look like thisSET ID Product Attribute1 A 101 A 112 A 102 A 12Thank you all in advance for your help.

Convert character data to decimal

Posted: 19 Aug 2013 03:17 AM PDT

I have some data coming in with leading 0s as well a +/-.You can see what I have tried so far. I don't understand why the negative numbers are not being handled correctly.Thanks if you have a suggestion or a better way to do this.[code="sql"]CREATE TABLE #Test(TestData varchar(50))INSERT INTO #Test SELECT '+000000000000760.00'INSERT INTO #Test SELECT '+000004532078501.60'INSERT INTO #Test SELECT '-000000001224249.00'INSERT INTO #Test SELECT '+000000000468181.00'SELECT * FROM #TestSELECT CASE LEFT(TestData,1)WHEN '+' THEN CONVERT(decimal (18,2),REPLACE(LTRIM(REPLACE(TestData,'0',' ')),' ','0')) WHEN '-' THEN - CONVERT(decimal (18,2),REPLACE(LTRIM(REPLACE(TestData,'0',' ')),' ','0')) END FROM #TestDROP TABLE #Test[/code]

unable to add diagrams

Posted: 19 Aug 2013 06:40 AM PDT

When I try to add it I get error saying that the database needs valid owner.On the "General" screen there is an Active Directory owner.but on the Files screen the owner is blank.Why is that and why do I need to have an owner there?Thanks,Tom

[SQL Server 2008 issues] Select specific set of data from text column

[SQL Server 2008 issues] Select specific set of data from text column


Select specific set of data from text column

Posted: 19 Aug 2013 03:45 PM PDT

Hi Experts,How can i select the data from a table where the data is as follows.Requirement: Select rows from the table where the log entry is as "Number of Files count= 'is greater than zero" The query should select the related rows of that whole process.Following sample data has two download events, one with 4 files and other with 2 files.The query output should select where the process files is greater than zero. ignore when no files were processedDateTime TextColumn2011-03-09 14:40:35.413 Prcessed Files count=02011-03-09 14:10:34.073 Prcessed Files count=2 --End 42011-03-09 14:10:34.390 Success download for Z345330 --32011-03-09 14:10:20.913 Success download for Z699090 --22011-03-09 14:09:56.667 Number of Files count=2 --Start 12011-03-09 13:39:55.280 Prcessed Files count=02011-03-09 13:09:53.940 Prcessed Files count=02011-03-09 12:39:52.770 Processed Files count=4 -- End 62011-03-09 12:39:53.190 Success download for Z294754 -- 52011-03-09 12:39:28.930 Success download for Z995876 --4 2011-03-09 12:39:03.183 Success download for Z940565 -- 32011-03-09 12:39:06.153 Success download for Z556433 -- 22011-03-09 12:38:39.730 Number of Files count=4 ----Start 1Sample Output2011-03-09 12:38:39.730 Number of Files count=4 -2011-03-09 12:39:06.153 Success download for Z5564332011-03-09 12:39:03.183 Success download for Z940565 2011-03-09 12:39:28.930 Success download for Z995876 2011-03-09 12:39:53.190 Success download for Z294754 2011-03-09 12:39:52.770 Processed Files count=4 2011-03-09 14:09:56.667 Number of Files count=2 2011-03-09 14:10:20.913 Success download for Z6990902011-03-09 14:10:34.390 Success download for Z345330 2011-03-09 14:10:34.073 Prcessed Files count=2

Creating a Test environment for a 10TB database

Posted: 19 Aug 2013 06:01 PM PDT

Hi All,Working on SQL Server 2008 R2 Enterprise Edt.Need to create a testing environment for this production server. One of the database's is 10TB in size. Database consists of multiple file groupsThe issue I'm having is there's not enough space on the Test server to do a full restore.Was thinking of creating a blank database then exporting data from Production to Test (all the data is not required)...but this will obviously effect the production server (this environment is 24/7)Just wanted to check if there are any other better ways of doing this...with no downtime on Production

xp_logininfo not finding user

Posted: 19 Aug 2013 04:47 AM PDT

I'm using xp_logininfo to find which domain group a user belongs to, and manipulate some controls in the application based on the results. I want to enable/disable various controls, depending on the privilege level of a user, so that a particular action is not possible for a user with insufficient privilege, rather than let them try it and have the app berate them them for the attempt.All the logic in the app works fine, but xp_logininfo is not locating one of my users. The command:[code="sql"]EXEC xp_logininfo 'nmp\zagorsekka'[/code]or [code="sql"]EXEC xp_logininfo 'nmp\zagorsekka', 'all'[/code]both give me the following error message.Msg 15404, Level 16, State 11, Procedure xp_logininfo, Line 62Could not obtain information about Windows NT group/user 'nmp\zagorsekka', error code 0xffff0002.[code="sql"]EXEC xp_logininfo 'nmp\zagorsekka', 'members'[/code]gives me nothing.The user DOES exist, and has been on this network for years - I just tried logging onto another computer using his credentials - no problem.The group to which he belongs is defined as a login and is mapped to the database. Also, another user in the same group works fine - returns the account name, type, privilege, mapped login name and permission path with no fuss. Is there something special that needs to be done with this SP? We do have a mirrored domain controller on site, while the main one is in another building across town.

How to find sql installed services on server

Posted: 19 Aug 2013 09:40 AM PDT

Hi Fnds,I am looking to find out ssis, ssrs, ssas installed on which server, i have several servers and i want find out those services on all servers. can any one help me?ThanksReally it'll be great help, if anyone can help?????Cheersmac

SQL backup on Cluster shared drive or Local drive.

Posted: 19 Aug 2013 03:46 PM PDT

I have a SQL server 2008 r2 cluster enviroment. Due to space constraints on the storage drive i had to move the backups from the shared storage drive to the local sql server. Now my server team has given me adequate space on the shared drive but from a best practice point of view i do not know whether it's better to keep the backups on shared drive or on the respective nodes local drive itself.Any suggestions ?

Google Analytics SQL Import

Posted: 08 May 2012 09:07 PM PDT

Hi AllI was just wondering if anyone has ever done a Google Analytics import to SQL via SSIS?A quick google brought up some C# scripts, a PHP web scraper and using the java client to export to CSV and then import it, but was wondering if anyone has managed to query the API and load it direct in SSIS to the DB?This was a task which was done a couple of years ago and I have been asked to re-ignite the flame to get it moving again and the previous way was to use xp_cmdshell to execute a file which loads it to CSV and imports it, which I have no trouble with, just wondering if anyone has a better solution.Thanks

sp_configure ‘user options’, 2

Posted: 19 Aug 2013 10:31 AM PDT

Hi,I accidentally ran the below command and I do not know what changes this command did. sp_configure 'user options', 2How to roll back the changes?Thanks

This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.

Posted: 19 Aug 2013 09:11 AM PDT

Hi Experts,Inititally when i tried to open Browser for ReportManager it gave me HTTP 500 Error.We opened web.config file and added as suggested in following link.http://myitforum.com/myitforumwp/2011/11/04/sql-srs-this-implementation-is-not-part-of-the-windows-platform-fips-validated-cryptographic-algorithms/Immediately i can see the report manager, with no HTTP Error. :)when i added rdl file and created data source to th reportmanager and tried to see report it is throwing me the following errorThis implementation is not part of the Windows Platform FIPS validated cryptographic algorithms. Any suggestion is appreciatedThanks

Backup during re-index

Posted: 19 Aug 2013 08:06 AM PDT

We have a database that at times can take up to 18 days to re-index. The database is in simple recovery model and runs a full backup every 12 hours to storage directory not on this SQL Server. Randomly the backup will fail with the following error messages to SQL logs.Error: 18210, Severity: 16, State: 1.BackupIoRequest::ReportIoError: write failure on backup device 'PATH\FileName.bak'. Operating system error 2(The system cannot find the file specified.).Error: 3041, Severity: 16, State: 1.BACKUP failed to complete the command BACKUP DATABASE dbname. Check the backup application log for detailed messages.Error: 3634, Severity: 16, State: 2.The operating system returned the error '64(The specified network name is no longer available.)' while attempting 'SetEndOfFile' on 'PATH\FileName.bak'.Error: 3634, Severity: 16, State: 2.The operating system returned the error '64(The specified network name is no longer available.)' while attempting 'FlushFileBuffers' on 'PATH\FileName.bak'.I feel this must be a network connection issue, but our network engineers are not seeing anything on their end. Is it possible re-index could cause something like this?

Restoring Database From Prod to UAT and Not Restoring USER,ROLES, SCHEMAS

Posted: 19 Aug 2013 08:51 AM PDT

Restoring Database From Prod to UAT and Not Restoring USER,ROLES, SCHEMAS what methods and scripts is available to do that.is there away to delete these users, roles and schemas before restoring into UAT server?how to fix user roles mismatch when orphan user scripts does not fix everything thanks I appreciate guys

SQL Server layout on a SAN

Posted: 19 Aug 2013 08:39 AM PDT

Ugh, every time I think I have my head wrapped around SAN technology; I realize I don't.SQL Server 2008 R2. Database in question is 3.9 TB. Here's what I know about my storage setup for my data files: I have 6 - 1 TB mount points. They are NetApp SCSI LUNs spread across 160 back-end spindles. I've read (in the NetApp documentation) that the Microsoft recommendation on multiprocessor servers is to have at least one LUN per logical processor.1) Does LUN equate to Mount Point? Or can I have several mount points but it really only be one LUN?2) In the case of a SAN; is there really any benefit to spreading data amongst multiple files in a single file group (placing each file on a different mount point)? Clearly if your SQL Server is using local hard disks the answer is yes; but I can't find anything conclusive on LUN setup. One one hand the data is already being spread across a bunch of drives so it seems like it wouldn't matter. On the other hand does having two specifically different files possibly help with performance.

Performance Issue: Where do you look?

Posted: 19 Aug 2013 07:55 AM PDT

I want to know your opinions when a customer says the database is slow today. Usually I would:*Check for blocking using the sp_who2*Check for statistics out of date (and perform update statistics)*Check for wait types*Identify fragmentation % (and then do an index reorg or rebuild accordingly)*Run profiler and identify deadlocks (or enable deadlock traceflags)*Run missing indexes script and check if any indexes are required*Run unused indexes script and check for indexes with 0 reads and delete them*Identify queries that are taking longer time to complete and tune them with DTA and add recommended indexes or statistics in a test env. first and move it to prod database*Check for IO bottlenecks by running the perfmon with appropriate counters from a remote machine*Verify with the network admins if there was a change in the network

virtual servers users lock each other

Posted: 19 Aug 2013 12:39 AM PDT

Hi Friends -thanks in advance for any help you can provid [URL=http://imgbox.com/adeQi0jc][IMG]http://t.imgbox.com/adeQi0jc.jpg[/IMG][/URL]As shown on the picture above, we have 5 virtual servers and 1 SQL server. (Windows Server 2008 R2 installed.)Users connect virtual servers via remote desktop.The problem is that users lock each other when they delete, update or select on servers. I checked sql profiler to see that sql server put the transactions in order. This ordering makes users lock each other. Is there a setting in the sql server to solve this problem?

DBA's facing customers...how do you handle?

Posted: 15 Aug 2013 12:50 AM PDT

I think this post is relevant here and I am curious to know DBAs thoughts on facing the toughest customers. How do you manage it?This is not something technical but would like to see everyone's experiences with their toughest customers:-)

unable to install sql management studio 2008 R2

Posted: 19 Aug 2013 05:53 AM PDT

Running Windows-7 Pro 32 bit. Trying to start SQL Server Agent. It is stopped & greyed out so cannot be started. Tried to install SQL Management Studio 2008 R2, get Validation Errors unable to install. Is there any quick way I can get the SQL Server Agent to run and/or install the above SQL Managemnet Studio?Thanks for any help

Find the Slow Running query.

Posted: 19 Aug 2013 03:01 AM PDT

Hi Team,am having a online application, while doing some actions like (select drop down, select any item from list), application is taking long time (10 seconds), previously it was done with in fraction of seconds.how to identify the query which is taking time, using below query but am not getting the exact result, SELECT TOP 10 a.total_worker_time/a.execution_count AS [High CPU Ave], SUBSTRING(b.text,a.statement_start_offset/2, (CASE WHEN a.statement_END_offset = -1 then len(convert(nvarchar(max), b.text)) * 2 ELSE a.statement_END_offset END -a.statement_start_offset)/2) AS SQL_Text, db_name(b.dbid) AS DatabaseName, object_name(b.objectid) AS ObjectName FROM sys.dm_exec_query_stats a CROSS APPLY sys.dm_exec_sql_text(a.sql_handle) as b ORDER BY [High CPU Ave] DESC GO

Maximum row size of 8060

Posted: 19 Aug 2013 12:10 AM PDT

In SQL Server 2008r2, the maximum row size of 8060 is not applicable to [url=http://technet.microsoft.com/en-us/library/ms186981(v=sql.105).aspx] varchar(max), nvarchar(max), varbinary(max), text, image, or xml[/url] columns. I thought that this was a statement of fact, but I'm having some difficulties with an upgrade test for a backup of one of our customer databases to the latest version of our schema. The table in question has 23 columns and we're adding 2 new columns. 1 column is an XML column, all of the rest are fixed width columns (no TEXT, no IMAGE, no MAX size). I ran through the upgrade script for that table, it essentially drops the msrepl_tran_version column, adds two new columns (CHAR(1) and BIGINT) then adds the msrepl_tran_version (UNIQUEIDENTIFIER) column back with the default constraint of NEWID() [i](I know that none of this is necessary, it's something we have to do with our OEM version of the software because the guys we OEM to insist on ordinal positions of columns being the same and msrepl_tran_version always being the last column)[/i].Anyway, whilst adding the column back I get the following error: -[code="plain"]Msg 511, Level 16, State 1, Line 4Cannot create a row of size 8063 which is greater than the allowable maximum row size of 8060.[/code]I wrote a script to take a look at the data, as I assume that this is a data issue since upgrading a blank version of this schema to the latest one has no issue but can't see any issues. When I run the script like this: -[code="sql"]DECLARE @table VARCHAR(30) = 'TB_DIM_ITEM_PKEY_MAP', @idcol VARCHAR(20) = 'PKEY_MAP_URN', @sql NVARCHAR(MAX);SET @sql = 'SELECT ' + @idcol + ' , ROW_SIZE = (0';SELECT @sql = @sql + ' + ISNULL(DATALENGTH(' + NAME + '), 1)'FROM syscolumnsWHERE id = object_id(@table) --AND name <> 'XML_DATA';SET @sql = @sql + ') FROM ' + @table + ' ORDER BY ROW_SIZE DESC';EXEC sp_executesql @sql;[/code]The biggest row size is '130273', however if I uncomment the XML_DATA part to exclude the XML column then the biggest row size is '190'. So, I can't honestly see the issue. I've setup a test where I am inserting the data from this table to a copy of the table with the new definitions, one row at a time, to see if I can find the "bad" data. But since there is a lot of data in the table, this will take some time. I was wondering if someone else had come across the same issue? Or if someone knows more about it than me? ;-)

Job duration

Posted: 03 Feb 2012 07:53 PM PST

Hi ,Can any one tell me how to know the duration of job that was run last time.

can not create temp directory

Posted: 06 Aug 2013 09:37 PM PDT

Hi All,I am getting below error.can not create temp directoryPlease advice on this.

Search This Blog